I'm fairly new to the Laravel. I implemented AUTH in laravel with 3 roles. I've HomeController with index function where I'm checking for what is the role of the logged in user and depending upon the role I want to load the view. I'm not able to get how do I change the route name from /home to /superadmin. When I load view it only shows me text but the route is still /home. I know it must have been answered somewhere but nothing is working for me right now.
I've tried this
Redirect::to('superadmin.page1')->with($data);
return view('superadmin.page1')->with($data);
return redirect()->route('superadmin');
return view('superadmin.page1');
HomeController.php //main code
try
{
if(count($data) < 0)
{
return view('user.page1')->with($data);
}
else
{
//super admin ko pehle check karo , then admin , then user
$role_array = array();
foreach ($data as $key => $value) {
$role = $value->role_name;
array_push($role_array , $role);
}
if (in_array("ROLE_SUPERADMIN", $role_array))
{
return view('superadmin.page1')->with($data);
}
else if (in_array("ROLE_ADMIN", $role_array))
{
return view('admin.page1')->with($data);
}
else
{
// undefined role found, therefore user
return view('user.page1')->with($data);
}
}
}
==========
My route
Auth::routes();
Route::get('/home', 'HomeController@index');
Route::get('/superadmin', 'SuperAdminController@index');
Route::get('/superadminPage1', 'SuperAdminController@page1');
I'm getting this as output
@extends('layouts.app') @section('content')
SuperAdmin Page1
@if (session('status'))
{{ session('status') }}
@endif This is SuperAdmin PAGE1. You must be privileged to be here !
@endsection