0
votes

am facing a problem whereby after assigning a role to a user(whose value in the db is_admin value is 0) as an admin(whose value in the db is_admin value is 1) its unable to change back the role to a user from admin.i haven't understood the reason why coz Ive added the necessary database check in the update function..here is my update function in the adminscontroller

/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param \App\Models\User $user * @return \Illuminate\Http\Response */ public function update(Request $request,User $user ) {

    $role=Role::where('id',$request->rolename)->first();
      if($role->Role_name!=='Regular User' && $user->is_admin=1)
      {
         $user->roles()->sync($role);
      }
     elseif($role->Role_name!=='Regular User' && $user->is_admin=1){
         $user->roles()->sync($role);
         $user->update(['is_admin'=>0]);
     }
    //  dd($role);
    return redirect()->route('admins.index')->withsuccess (Ucwords($user->name). 'has been Updated Successfully');
    
}

i will provide any necessary details on request

1

1 Answers

0
votes

could you make a dd($role=Role::where('id',$request->rolename)->first())? I think this isn't well, you are comparing in where clause "id" with "rolename"... your value is_admin in the db which type is, boolean?