class Profile extends Eloquent {
protected $fillable = array('name', 'last_name', 'website', 'facebook', 'twitter', 'linkedin', 'google_plus');
public static function boot(){
parent::boot();
self::updating(function($model){
$model->name = Crypt::encrypt($model->name);
$model->last_name = Crypt::encrypt($model->last_name);
$model->facebook = Crypt::encrypt($model->facebook);
$model->twitter = Crypt::encrypt($model->twitter);
$model->linkedin = Crypt::encrypt($model->linkedin);
$model->website = Crypt::encrypt($model->website);
$model->google_plus = Crypt::encrypt($model->google_plus);
});
}
}
我正在使用 too call 事件..
$user->profile()->update(array(
'name' => e($input['name']),
'last_name' => e($input['last_name']),
'website' => e($input['website']),
'facebook' => e($input['facebook']),
'twitter' => e($input['twitter']),
'linkedin' => e($input['linkedin']),
'google_plus' => e($input['google_plus'])
));
出于某种原因,它没有触发任何事件... 我试图在将用户信息保存到数据库之前对其进行加密
最佳答案
只有在调用 save() 方法时才会触发启动事件,而不是您正在使用的 update() 方法。
关于php - Laravel 模型事件更新()未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24484621/