kirschbaum-development / nova-mail

A Laravel Nova action that provides a mail sending form for any resource
MIT License
73 stars 25 forks source link

Policy error when extending User model. #26

Closed crumb1e closed 3 years ago

crumb1e commented 4 years ago

I'm extending my User already, so I am unable to extend the Illuminate\Foundation\Auth\User model in order for the NovaSentMailPolicy to work.

Results in the following error when accessing the nova admin:

Argument 1 passed to KirschbaumDevelopment\NovaMail\Policies\NovaSentMailPolicy::create()
must be an instance of Illuminate\Foundation\Auth\User, instance of App\User given.

Looks like this was changed in PR #17, not sure what a good workaround would be, maybe a config value for the User model?

crumb1e commented 4 years ago

Just incase anyone else comes across this, as a workaround for now, I have extended the SentMailPolicy and added it into my AuthServiceProvider.

// app/Providers/AuthServiceProvider

protected $policies = [
    // ...
    \KirschbaumDevelopment\NovaMail\Models\NovaSentMail::class => 'App\Policies\NovaSentMailPolicy',
    // ...
]
brandonferens commented 4 years ago

@crumb1e This really is a good point. I'm assuming that your user is still implementing Illuminate\Contracts\Auth\Authenticatable which is the contract necessary for being logged in. Perhaps the code committed in PR #17 should be altered to resolve the $user model from that contract instead. Do you think that would solve the issue?

Would you mind testing that for us and if it fixes it, issue a PR? If not, that's cool, I will try and resolve it.

adammparker commented 3 years ago

Solved in the latest release, thanks!

https://github.com/kirschbaum-development/nova-mail/releases/tag/1.0.2