The Eloquent ORM provides a beautiful, simple ActiveRecord implementation for working with your database.
The results of Eloquent queries are always returned as Collection instances and Eloquent has a list of methods to work with Collections.
Here it is an interesting article about 10 less-known Eloquent collections methods:
avg()
chunk()
contains()
every()
filter()
forget()
implode()
keyBy()
map()
plunk()
domenica 26 novembre 2017
Howto preview sql query code generated in Eloquent
The simplest method to show the query generated by Eloquent is by utilizing a ->toSql() method.
We only need to replace the closing ->get() with ->toSql() and then print out the results with dd() or die() funnction.
Here is an example:
This is the output:
A little more complex and complete way is to enable and use the QueryLog method.
Here the example:
This is the output:
We only need to replace the closing ->get() with ->toSql() and then print out the results with dd() or die() funnction.
Here is an example:
$users = DB::table('users')
->where('email', 'x@y.xxx')
->where('is_active', true)
->toSql();
// ->get();
dd($users);
This is the output:
"select * from `users` where `name` = ? and `is_active` = ?"
A little more complex and complete way is to enable and use the QueryLog method.
Here the example:
DB::enableQueryLog(); $users = DB::table('users') ->where('email', 'x@y.xxx') ->get(); dd(DB::getQueryLog());
This is the output:
array:1 [▼ 0 => array:3 [▼ "query" => "select * from `users` where `email` = ?" "bindings" => array:1 [▼ 0 => "x@y.xxx" ] "time" => 61.13 ] ]
domenica 12 novembre 2017
Linux commands and tools for networking and sysadmin
I 20 comandi indispensabili per un amministratore di sistema.
20 Linux commands every sysadmin should know
Comandi e tools linux interessanti per il networking.
https://itsubuntu.com/linux-networking-commands-and-scripts/
20 Linux commands every sysadmin should know
Comandi e tools linux interessanti per il networking.
https://itsubuntu.com/linux-networking-commands-and-scripts/
lunedì 17 luglio 2017
Ricerca in VIM
Comandi per ricercare una stringa in un file con l'editor VIM:
/ + ENTER
Per passare all'occorrenza successiva premere "n"
Per passare all'occorrenza precedente premere "N"
/
Per passare all'occorrenza successiva premere "n"
Per passare all'occorrenza precedente premere "N"
venerdì 30 giugno 2017
Aumentare la dimensione massima di file caricabili sul server in post
Occorre intervenire su sulla configurazione di PHP e sul web server.
Ipotizziamo di utilizzare un macchina Ubuntu 16.04 con PHP 7.0 e web server nginx.
Per quanto riguarda php occorre modificare nel file php.ini i valori dei parametri
upload_max_filesize
post_max_size
Per quanto riguarda il server web, ipotizzando di utilizzare nginx,
In caso di file di dimensioni particolarmente elevate occorre intervenire anche sul tempo massimo di durata dello script sia in PHP che in nginx
Finite le modifiche ricordarsi di riavviare PHP e nginx
sudo service php7.0-fpm restart
sudo service nginx restart
Riferimenti
Ipotizziamo di utilizzare un macchina Ubuntu 16.04 con PHP 7.0 e web server nginx.
Per quanto riguarda php occorre modificare nel file php.ini i valori dei parametri
upload_max_filesize
post_max_size
Per quanto riguarda il server web, ipotizzando di utilizzare nginx,
- in caso di modifica per tutto il server occorre modificare il file nginx.conf inserendo il valore client_max_body_size nel blocco http
- in caso di modifica per un solo dominio occorre modificare il file di configurazione del dominio (/etc/nginx/sites-avalible/
.conf) inserendo la stesso stringa nel blocco server
In caso di file di dimensioni particolarmente elevate occorre intervenire anche sul tempo massimo di durata dello script sia in PHP che in nginx
Finite le modifiche ricordarsi di riavviare PHP e nginx
sudo service php7.0-fpm restart
sudo service nginx restart
Riferimenti
- https://easyengine.io/tutorials/php/increase-file-upload-size-limit/
- https://easyengine.io/tutorials/php/increase-script-execution-time/
Iscriviti a:
Post (Atom)