You need to return a Boolean every time.
return !$this->is_published ?? true;
Hi! I'm running into an issue with Nova's action ->canSee() method, when the action updates the model and that update itself changes the return value of the ->canSee() callback.
The use case is that I have a Book model, which could be published or not. This is managed through a 'published_at' column, with an attribute getter $book->is_published. I want to show a Publish action on the BookResource details page when the Book is currently in draft, otherwise hide it:
public function actions(NovaRequest $request)
{
return [
PublishModelNovaAction::make()->canSee(function () {
return !$this->is_published;
})
];
}
The handle() method of the action is simple:
public function handle(ActionFields $fields, Collection $models)
{
foreach ($models as $model) {
$model->publish();
}
return Action::message('Models published.');
}
However, the issue is that once the Book gets published, the canSee() method no longer returns true, and therefore just throws a 403. I assume this is because the canSee() method is run both on page load and also once the action completes? Any ideas of how to get around this? The same issue occurs with the canRun() method.
Thanks!
Please or to participate in this conversation.