我有Team
有口才,有TeamObserver
。 TeamObserver
有deleting event
,如果我打电话给TeamDeletingEvent
。 TeamDeletingEvent
分派TeamDeletingListener
。如果TeamDeletingLister
返回false会停止团队删除功能吗?
TeamObserver
class TeamObserver
{
/**
* Handle the team "deleting" event.
*
* @param Team $team
* @return void
*/
public function deleting(Team $team)
{
event(new TeamDeletingEvent($team));
}
}
TeamDeletingEvent
class TeamDeletingEvent
{
use SerializesModels;
/**
* @var Team
*/
public $team;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct(Team $team)
{
$this->team = $team;
}
}
TeamDeletingListener
class TeamDeletingListener
{
/**
* Handle the event.
*
* @param TeamDeletingEvent $event
* @return bool
*/
public function handle(TeamDeletingEvent $event)
{
$teamUser = Team::where('id', $event->team->id)->users()->first();
if(is_null($teamUser)){
return true;
}
return false;
}
}
除了TeamObserver
和AppServiceProvider
Event and Listener
中注册的EventServiceProvider
答案 0 :(得分:1)
侦听器返回false不会停止删除功能。它将停止事件的连续侦听器调用。但是,雄辩的事件返回false将停止删除功能。 (模型实例值已更新,但数据库中未更新)。更多信息Detail Answer