Home > Article > PHP Framework > Introduction to super practical functions in laravel framework
This article brings you an introduction to the super practical functions in the laravel framework. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
Make lumen's dd() dump() as elegant as laravel
composer require symfony/var-dumper
Get the executed sql statement
Can view sql where parameters, etc.
public function index() { DB::connection()->enableQueryLog(); // 开启查询日志 DB::table('posts')->paginate(5); //要查看的sql $queries = DB::getQueryLog(); // 获取查询日志 dd($queries); // 即可查看执行的sql,执行的时间,传入的参数等等 }
Can only view simple sql but cannot see the incoming parameters
DB::table('posts')->toSql();
Query sql records
If, you want to save the log files in the storage/logs directory. Needs to be updated: The boot() function in app/Providers/AppServiceProvider.php
b57a13a3c6862a6dbc56528efb34422csql, $query->bindings, $query->time ); }); } /** * Register any application services. * * @return void */ public function register() { // } }
Laravel How to get the value of a field before modification in the model event
Issue::saving(function(Issue $issue){ if ($issue->isDirty('title')) { $user = Auth::user()->username; $oldTitle = $issue->getOriginal('title'); // 原始值 $newTitle = $issue->title; // 新值 ActionLog::log("$user 把标题 $oldTitle 修改为 $newTitle"); } });
The above is the detailed content of Introduction to super practical functions in laravel framework. For more information, please follow other related articles on the PHP Chinese website!