我正在尝试在action中触发observer。看起来像这样:
class ClientObserver
{
/**
* @param Client $client
* @return mixed
*/
public function created(Client $client)
{
$request = new ActionRequest();
$action = app(HarvestClientCreate::class);
$collection = Collection::wrap($client);
return DispatchAction::forModels(
$request, $action, 'handle', $collection
);
}
}
但是这不起作用!我收到此错误:
Call to a member function getKey() on null
/projects/crm-nova/vendor/laravel/nova/src/Actions/ActionEvent.php", line: 193
当我追踪到它时,它在ActionEvent.php
中出了错:
'user_id' => $request->user()->getKey(),
但是当我根据请求手动设置用户时,它不能正常工作。
这里可能出什么问题了?