dimanche 14 juillet 2019

how to fix Undefined variable: users in laravel view

I'm using this package spatie-laravel-permission

to add roles and permissions to my website.

in my admin dashboard, I fetched all users and set a delete method.


public function user_destroy ($id){

        $user_delete= User::findOrFail($id);

            $user_delete->removeRole($user_delete->getRoleNames());
            $user_delete->delete();


        return view('admin.users.index')->with('success','User is deleted');
    }


so using the code above does not remove the user and his role.

I get this error :

Return value of App\User::getStoredRole() must implement interface Spatie\Permission\Contracts\Role, instance of Illuminate\Support\Collection returned



i tried to use PHP detach() :

 $user_delete->roles()->detach();


It is actually working but I get this error :

Undefined variable: users (View: resources\views\admin\users\index.blade.php)

The PHP $users are defined in the index view like this :


public function mainUsers(){

       $users = User::latest()->paginate(5);
       return view('admin.users.index',compact('users'));

   }




via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire