Closed ph1llips closed 1 year ago
Hi.
I can understand your need to use the Nova guard, if defined.
Although Nova by default does not come with its own guard but uses the Laravel default one
I tested your code and when I have not created a custom Nova guard then
config()->has('nova.guard')
would still return true, due to the config existing out of the box in config/nova.php
as 'guard' => env('NOVA_GUARD', null),
And afterwards the user would still default to the default guard provided by Laravel.
$user = Auth::guard(config('nova.guard'))->user();
Either please add a check if the Nova guard is not null as well or if you have a specific need you can utilize the Custom delete authorization gate detailed here.
Right now this pull request does not actually validate if a Nova guard is set up.
I've changed the config->has to config->get as that will return NULL if is not set and therefore will actually validate if a Nova guard has been set up.
@richard-raadi Hello
I believe that you should also change $user = $user ? Auth::user() : null;
to $user = $user ? Auth::guard(config('nova.guard'))->user() : null;
inside the addNote
method inside the HasNotes
trait.
Without this, I do not get any user when creating a note in nova. That is because my config/auth
has the default guard set to api
instead of web
. While my nova_guard is set to the default web
Many thanks
The getCanDeleteAttribute() method retrieves the authenticated user with the default guard instead of using the guard configured for nova.