skip to Main Content

I have this code `

User::first()->attachPermission($permission);

which select first user in table user, but I want to select all user from user table. I create

User::get()->all()->attachPermission($permission);

but this not working

2

Answers


  1. Just simply use

      User::all();
    

    OR

      User::get();
    
    Login or Signup to reply.
  2. To attach permissions, you just need to add them to the iteration using either all() or get() as shown by @aynber and @Telexx:

    $users = User::get();
    
    foreach($users as $user){
        $user->attachPermission($permission);
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search