I'm trying to fire an action in an observer. It looks like this:
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
);
}
}
But this is not working! I get this error:
Call to a member function getKey() on null
/projects/crm-nova/vendor/laravel/nova/src/Actions/ActionEvent.php", line: 193
When I trace that down it goes wrong in ActionEvent.php
:
'user_id' => $request->user()->getKey(),
But when I set the user manually on the request it's not working as wel.
What could be going wrong here?