Posts by gmsantos • 17,221 points
395 posts
-
3
votes1
answer345
viewsA: How to check credentials before authenticating to Laravel 5.3?
You can use the method attempt of the component of Auth for that reason. With this method it will already perform the authentication for you, without having to redirect again to the native method.…
-
2
votes3
answers380
viewsA: Use variables outside the function
I think you want to do this with anonymous functions. Also known as clousures, are available from the PHP 5.3: $agua = '1 Litro'; $garraga = function ($item1,$item2) use ($agua) { return 'Lista:…
-
1
votes2
answers221
viewsA: Merge project when using the "Composer create-project" command
You can make a script for such a, a . sh that runs Composer create-project, downloads your repository and leaves it for you to resolve code conflicts, or else compare to the base repository with git…
-
1
votes2
answers98
viewsA: How to relate two records in an elegant way?
In your Post you can also use the associate. It will insert the user ID in your Post. See on documentation. public function adicionar(CadEditPost $request) { $post = new Post($request->all());…
-
3
votes1
answer1366
viewsA: PHP7 does not work with SQL Server 2014
PHP extension Dlls are compiled to work in a single version of PHP. The PHP 5.6 DLL will lock in PHP 7, and the PHP 7 DLL will lock in PHP 7.1. So, at first, make sure you’re using only the correct…
-
5
votes2
answers1049
viewsA: PHP 7 already has stable version for production?
Yes, PHP 7 is stable now for more than a year, launched in 5 de December de 2015. Currently the latest stable version is 7.1, launched in December of that year. To upgrade to the latest version,…
-
1
votes1
answer2928
viewsA: How to update Docker-Compose
Docker Compose update will depend on the system you are using. On Windows and macos they are updated along with the Docker installer on these platforms, which is not when we update Docker from a…
-
1
votes1
answer85
viewsA: Webservice Php without Lib
Roughly, both can be considered webservices yes. What changes between them is the pattern to be used. In the first case there is no pattern, only a confirmation message and nothing else. Error…
-
2
votes1
answer133
viewsA: Autoload controllers using namespace
The problem is how you’re instantiated your class. Do not mix the object declaration with strings, because it won’t work. Instead, concatenate the class name with the namespace expected in a string:…
-
13
votes2
answers13586
viewsA: How to install the PDO_PGSQL driver in Ubuntu?
On Linux systems the installation of extensions is a little different. The extensions are not there by default, but we can install with the apt-get: sudo apt install php-pgsql Depending on your…
-
0
votes2
answers3637
viewsA: Filter records by month and year in Laravel
Being a field of sorts date, you can format the date before comparison. In your repository create a method similar to this // Em MySQL, por usar uma raw public function findByBatata($type, $date,…
-
3
votes1
answer90
viewsA: Doubt to bring mysql data
We can break this problem down into two parts. First we need to count the amount of sales by city and state: SELECT cidade, estado, count(*) FROM vendas GROUP BY cidade, estado ORDER BY estado,…
-
6
votes3
answers505
viewsA: What are the native exceptions of PHP?
Of the native exceptions, it is good to know that some extend others, forming the next hierarchy: Logicexception (extends Exception) Badfunctioncallexception Badmethodcallexception Domainexception…
-
3
votes3
answers148
views -
3
votes1
answer153
viewsA: Showing Results other than a column
From what I understand you would have a box table similar to this: | COD_FILIAL | TIPO | DATA | |------------|------|----------| | 1 | 00 | 20160101 | | 1 | 99 | 20160101 | | 2 | 00 | 20160101 | | 2…
-
2
votes3
answers717
viewsA: How to list files in a directory?
You can use the method isDot() to check if the item is a browser between directories. <?php $path = 'pasta_desejada'; $dir = new DirectoryIterator($path); foreach ($dir as $item) { if (!…
-
1
votes4
answers1278
viewsA: Difficulty with MSSQL and PHP on Centos 6 server
Some things have changed from the question post to the days. Version 4 of the SQL Server driver supports the client using Linux. https://github.com/Azure/msphpsql/tree/PHP-7.0-Linux It has as…
-
1
votes3
answers1906
views -
2
votes2
answers3070
viewsA: How to see the queries that were executed by the eloquent in Laravel?
Another way to see the darlings executed by a request directly in the browse is through the Laravel-debugbar. It is compatible with Laravel 4 and 5, and has a tab that shows all darlings. It even…
-
9
votes2
answers1508
viewsA: Choice of hash generation method in PHP
With that in mind, as far as I can consider this thought as correct and start using only the password_*? method if fit the ideal requirements for hashing? The purpose of the PHP password API is to…
-
7
votes2
answers15531
viewsA: How to find the version of Laravel installed in my project?
You can use Composer for this too: composer show laravel/framework In the first lines you can check the installed version: λ composer show laravel/framework name : laravel/framework descrip. : The…
-
0
votes1
answer116
viewsA: How to create a project based on Laravel to be the basis of others?
As you pointed out yourself, creating a project that will be used as a base will not create a dependency with the initial base. The repository will be cloned and later updates need to be done…
-
1
votes1
answer319
viewsA: Mongodb extension not found in PHP 5.6
When using Mongodb with PHP we have to keep in mind that there are two versions of drivers. We have the extension mongo and the extension mongodb, the second being the latest version. The driver you…
-
0
votes2
answers200
viewsA: How to send email without a view
The correct in this case would be to use the method raw and not the send Mail::raw('CORPO DA MENSAGEM DE EMAIL TESTE!!!', function ($message) { $message->to('[email protected]')…
-
2
votes1
answer761
viewsA: Lumen and Firebird Database
Lumen and Eloquent can be used in a Firebird database that is already used by another application, without the ORM making changes in the database structure? Yes, it is possible. Eloquent does not…
-
2
votes1
answer63
viewsA: I want example of why replacing ' with '' and for parameters of a query is dangerous
In your example the insertion is actually escaping the characters in order to avoid Injection. Ok. The big problem is just the way you’re gonna do it: whereas even int will enter into this procedure…
-
1
votes1
answer197
viewsA: Running Websocket directly in php class
For the development environment, the command is the simplest way to execute. You must somehow have the process running in parallel to listen to the requests sent. An alternative would be to create…
-
2
votes2
answers827
viewsA: Remove duplicated data and return the highest value date field
If the column is set to date type, it is possible to do this directly in Mysql (it should work in Access as well): SELECT id, MAX(some_date) FROM old_table GROUP BY id; That one query will group the…
-
2
votes1
answer561
viewsA: Class with more than one __constructor in PHP?
In theory it is not possible for a class to have more than one constructor in PHP. Because it is a dynamic language, overloading of methods does not house very well. What exists in PHP are two ways…
-
4
votes1
answer7829
viewsA: php Artisan command serves by running multiple hosts
There’s a conflict at door 80 of your machine. You need to change the door of the second application. Only the hostname is not enough because it is only an alias for localhost: php artisan serve…
-
4
votes1
answer982
viewsA: How to use Laravel Facades outside of its structure?
It’s not that simple, Anderson. Laravel like any other framework usually needs to be initialized, as there are many other things that need to be running before using the classes themselves. In the…
-
1
votes1
answer302
viewsA: How do I run a.php file?
You can execute a command for the operating system using crases together with the console command: $retorno = `php -f week.php`; See an example on Ideone. It is important to note whether the…
-
1
votes2
answers222
viewsA: How to include values in the same Section without overwriting the previous one?
At Laravel 5.2 we have the @stack to do this, changing few things: #layout.blade.php <head>@stack('javascripts')</head> <div id="container">@yield('container')</div>…
-
3
votes1
answer1028
viewsA: Difference between new project command and create-project command
The difference between them is very subtle. Both will use Composer to install the dependencies of your project. The difference is that the --prefer-dist will download from the releases of the…
-
3
votes2
answers11627
viewsA: Convert "hh:mm:ss" to int minutes
Assuming you are using a date type to store your data, you don’t even need a function for it, just use the DATEDIFF SELECT DATEDIFF(second, 0, '20:10:10') AS diferenca_em_segundos Example in SQL…
-
0
votes2
answers431
viewsA: Creating a website and back-end with PHP frameworks
What is most important to you? Application execution or development speed? Although the micro framework is naturally lighter, it will not have all the features of a full stack framework, which…
-
8
votes3
answers247
viewsA: What is "One Level of indentation"?
This type of recommendation is independent of language. Don’t get too attached to project or coding default settings, or if something comes from Microsoft or PHP. Try to separate the concept from…
terminologyanswered gmsantos 17,221 -
1
votes1
answer592
viewsA: How to Connect to Database by Reading INI File (Function and Class)
You are mixing the class definition with the object instantiation. You do not pass the = so directly. You need to do something this way: <?php // Aqui vem a definação da classe class Banco { //…
-
3
votes1
answer400
viewsA: Check which field already exists in the table
The easiest way to do this is by using the rule unique Validator before registering your user. If you are using Laravel 5+, check the validation rules in your AuthController, let it look like this:…
-
5
votes3
answers3733
viewsA: Customize field name in validation error messages
Another way to customize the field name is directly in your language file by changing the key attributes /* |-------------------------------------------------------------------------- | Custom…
-
1
votes2
answers2904
viewsA: How to redirect the authenticated user to a specific page?
In fact, by default Laravel will redirect you after logging in to the root of the site /, which in your case is 'Auth\AuthController@getLogin'. To change the redirect path if the user visits a…
-
0
votes2
answers251
viewsA: Update many fields of a model
Basically you look for the method update: public function postEdit($id, Request $request){ $produto = Produto::findOrFail($id); $produto->update($request->all()); return…
-
2
votes2
answers346
viewsA: Standard Laravel Input Value
Laravel includes a helper that does just that: array_get($array, 'campo', 'valor padrão'); // null como default The advantage is that you can do this anywhere, not necessarily only on input.…
-
0
votes1
answer126
viewsA: Problems using Query Builder in Laravel
The way you’re doing $putentes is an array. You need to iterate these guys before accessing the property name: Assuming you’re using Blade: @foreach($putentes as $putente) {{$putente->nome}}…
-
1
votes1
answer779
viewsA: How to restrict access to user registration page?
Simply change the authentication controller middlewares to: /** * Create a new authentication controller instance. * * @return void */ public function __construct() { $this->middleware('guest',…
-
3
votes4
answers158
viewsA: Passing argument by PHP array
From PHP 5.6, you can use argument unpacking function exec($dia, $mes, $ano){ // faz algo } $as = [ [1, 2, 2016], [2, 2, 2016], [3, 2, 2016], ]; foreach($as as $a){ exec(...$a); };…
-
5
votes1
answer178
viewsA: Why doesn’t the regex work?
While trying to execute your code I got the following feedback: <?php function countWords($sentence) { $newsentence = preg_replace("/\s+/"," ",$sentence); return count(split(" ", $newsentence));…
-
3
votes1
answer1000
viewsA: How does Laravel 5 make an instance to be passed automatically if we just set Type Hinting in the parameter in a function?
This is only possible thanks to Service Container of Laravel. It is an implementation of Ioc (Inversion of Control) and DI (Dependency Injection) which aims to reduce coupling between classes and…
-
1
votes2
answers236
viewsA: Class does not extend from another
You are misimplemented your child class. I don’t understand the purpose of the template class, but for what you want to do this is enough: class Spinxo extends Template { public function load() {…
-
2
votes1
answer251
viewsA: Which PHP extension should I use with SQL Server 2000?
Unfortunately this version of SQL Server Native Client does not work with SQL. Server 2000. You need to use Microsoft Drivers 2.0 for PHP for SQL Server in this case and Microsoft SQL Server 2008 R2…