Php Laravel 4模型关系事件?
创建新模型关系时是否有触发的事件?e、 gPhp Laravel 4模型关系事件?,php,events,laravel,laravel-4,eloquent,Php,Events,Laravel,Laravel 4,Eloquent,创建新模型关系时是否有触发的事件?e、 g $comment = Comment::create( array('title' => 'hello world!') ); $post->comments()->save($comment); 保存“评论到帖子”关系时是否触发任何事件?这在某些用例中非常方便 例如,在我的应用程序中,我有用户和组织。当我向组织中添加用户时: $user->organisations()->save($organisation);
$comment = Comment::create( array('title' => 'hello world!') );
$post->comments()->save($comment);
保存“评论到帖子”关系时是否触发任何事件?这在某些用例中非常方便
例如,在我的应用程序中,我有用户和组织。当我向组织中添加用户时:
$user->organisations()->save($organisation);
我希望这能触发一个事件,我可以将用户绑定到组织权限组。我想你可以注册模型观察员 从文档中:
class UserObserver {
public function saving($model)
{
//
}
public function saved($model)
{
//
}
}
User::observe(new UserObserver);
我从未使用过它们,我不确定它们是否对您的场景是必要的,但我认为如果您真的想这样做,这是一种方法