圣诞快乐的家伙!
原文链接:https://www.f2er.com/laravel/133306.html我是Laravel的新手.刚刚有一个初学者的问题,当我尝试使用服务提供者和模型事件来记录更新信息时.
遵循在线文档:https://laravel.com/docs/5.3/eloquent#events
将所有代码放在一起后,我发现模型事件仅在创建使用时触发,但在编辑用户时从不记录任何内容.
我错过了什么吗?感觉$user没有被正确分配.这个从哪里来?来自其他服务提供商?
任何解释或提示将不胜感激!
<?PHP namespace App\Providers; use App\User; use Illuminate\Support\ServiceProvider; class AppServiceProvider extends ServiceProvider { /** * Bootstrap any application services. * * @return void */ public function boot() { User::creating(function ($user) { Log::info('event creating'); }); User::created(function ($user) { Log::info('event created'); }); User::updating(function ($user) { Log::info('event updating'); }); User::updated(function ($user) { Log::info('event updated'); }); User::saving(function ($user) { Log::info('event saving'); }); User::saved(function ($user) { Log::info('event saved'); }); User::deleting(function ($user) { Log::info('event deleting'); }); User::deleted(function ($user) { Log::info('event deleted'); }); } /** * Register the service provider. * * @return void */ public function register() { // } }