Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

hamzaNouali's avatar

my laravel accounts has become mixed

I have created a laravel application where the users are normal users and admin users... i login both of them to the website via the default laravel authentication... and i have middleware to hide some routes from normal users. but now i have a big problem... some times when i refresh the page I find my self in antoher account (example: now i am johne, refresh the page and i find my self jasmine)! .. i didn't face such a problem before :( , that problem now is rarely happen... I host now my application in a shared hosting.

 /* RoleMiddlware.php */
 public function handle($request, Closure $next,$role)
 {
   // $roles :
   // 0: user
   // 1: admin
   if(\Auth::user()['role'] != $role) return redirect('/');
   return $next($request);
 }

// in web.php i use the middlewate like this: 
Route::get(...)->middleware('role:1');
    
0 likes
2 replies
jlrdw's avatar

You should really take several weeks to thoroughly learn this stuff, before going into production. In some cases it would not hurt to take a few months. Work examples in the docs and watch some videos on authentication and authorization.

Please or to participate in this conversation.