outl1ne / nova-notes-field

This Laravel Nova package adds a notes field to Nova's arsenal of fields.
MIT License
51 stars 36 forks source link

Use Guard defined in Nova config #17

Closed adriandmitroca closed 4 years ago

adriandmitroca commented 4 years ago

Thanks to this change current User model is not hardcoded, also it inherits guard from Nova config which is used for entire authentication.

Use case: Admin as a separated model.

Tarpsvo commented 4 years ago

nova.guard is null by default, I might need to think of another solution here.

Tarpsvo commented 4 years ago

You could overwrite the Notes model and the createdBy() method, that'll work.

adriandmitroca commented 4 years ago

Hmm yeah that's option, but imho this should still respect Nova's guard. Perhaps with extra condition to check if guard is set instead of forcing it always?

Tarpsvo commented 4 years ago
$novaGuard = config('nova.guard');
$userClass = !empty($novaGuard)
    ? config('auth.providers.' . config('auth.guards.' . $novaGuard . '.provider') . '.model')
    : config('auth.providers.users.model');

Does this seem to suffice?

adriandmitroca commented 4 years ago

Exactly what I had in mind. I have just updated my PR :)

Tarpsvo commented 4 years ago

Cheers! Released in version 1.5.3.

adriandmitroca commented 4 years ago

I see that you have simplified code (https://github.com/optimistdigital/nova-notes-field/commit/2fcf0b8613d37d0b4269bd7bc7b864793f4d3b48) however this led to new bug.

Nova Guard isn't equal to auth provider, but auth guard instead. Based on that guard, you should search for relevant provider.

This was done here: https://github.com/optimistdigital/nova-notes-field/pull/17/files#diff-7a1e55e3c25f0de16f8bbfcea9501658R32

Currently, when nova.guard is set, you always get a null :(

Tarpsvo commented 4 years ago

Ah crap! That's pretty dumb, sorry about that! Released a fix in version 1.5.4. Thanks!

adriandmitroca commented 4 years ago

Thanks dude! It's great to be able to remove custom fork from composer.json 🤗