0

excuse me, i'm a junior developer and im still learn about laravel gates concept. i have a tables structure like this.

  1. Users = id, email, password, role_id.

  2. role = id, name, description.

  3. permission = id, name, slug.

  4. role_permission = permission_id, role_id. and this is my code

    $permission = Permission::all();

     foreach($permission as $p){
         Gate::define($p->slug, function(User $user) use ($p) {
             return $user->role_id === ???;
         });
     }
    

My Code

what should i return to protect gates, thanks.

im still learning about laravel gates concept, so i hope the other senior developers help me to explain about gates

  • 1
    Take a look at this package: https://spatie.be/docs/laravel-permission/v5/introduction Check the documentation and the implementation of it. It has a very good way to handle permissions. If it's possible for you, you could use it and save you some time with the detailed implementation. – Sergej Tihonov Jul 10 '23 at 23:40

0 Answers0