标签:binding void ted log tab tis space 添加 cti
providers
EventServiceProvider.php 添加
protected $listen = [ ‘Illuminate\Database\Events\QueryExecuted‘ => [ ‘App\Listeners\QueryListener‘ ] , ];
执行php artisan event:generate
会生成
QueryListener.php文件
<?php namespace App\Listeners; use Illuminate\Database\Events\QueryExecuted; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Support\Facades\Log; class QueryListener { /** * Create the event listener. * * @return void */ public function __construct() { // } /** * Handle the event. * * @param QueryExecuted $event * @return void */ public function handle(QueryExecuted $event) { $sql = str_replace("?", "‘%s‘", $event->sql); $log[‘sql‘] = vsprintf($sql, $event->bindings); Log::info(date("Y-m-d H:i:s")."(". $log[‘sql‘]).")"; } }
bootstrap文件添加
$app->register(App\Providers\EventServiceProvider::class);
标签:binding void ted log tab tis space 添加 cti
原文地址:https://www.cnblogs.com/php-linux/p/10676927.html