Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use policy #33

Closed
JeromeSiau opened this issue Dec 29, 2023 · 2 comments
Closed

Use policy #33

JeromeSiau opened this issue Dec 29, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@JeromeSiau
Copy link
Contributor

What happened?

I don't use Shield but I use very simple laravel policies

It seems my policy is ignored and I'm not sure how to fit it

How to reproduce the bug

  1. install plugin
  2. create a policy with the same name php artisan make:policy EmailPolicy
  3. Set return false in viewAny, the page should not be visible in the navigation anymore

It's the first time I'm trying to use a policy on a resource coming from a plugin so I might do something wrong

Package Version

1.0.10

PHP Version

8.2.14

Laravel Version

10.10

Which operating systems does with happen with?

macOS

Notes

No response

@JeromeSiau JeromeSiau added the bug Something isn't working label Dec 29, 2023
@JeromeSiau
Copy link
Contributor Author

JeromeSiau commented Dec 31, 2023

Hi,

I find out how to do it.
Laraval is not able to auto-discover policies when it's in the vendor directory, so you just need to help Laravel by manually registering the policy in the App\Providers\AuthServiceProvider

class AuthServiceProvider extends ServiceProvider
{
    /**
     * The model to policy mappings for the application.
     *
     * @var array<class-string, class-string>
     */
    protected $policies = [
        'RickDBCN\FilamentEmail\Models\Email' => 'App\Policies\EmailPolicy',
    ];
    
...

@stuartcusackie
Copy link

stuartcusackie commented Aug 13, 2024

This seems to have no effect on the menu item. I can't hide it with this method, and I don't use spatie roles on this project.
Laravel: 10.48.20, Filament Email: v1.5.1

Alternative solution is to use the config and add a custom hasRole() method to your user model.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants