I', trying to differentiate the user based on perspective role, i.e Admin, Supervisor, student etc. When admin or supervisor login it must go to their specific dashboard, and each user must not access other user's roles when one try access via ** URL * Im trying to do this using a single table USER adding additional field Role as type integer. Every time when I try to login as admin or supervisor I get an errorlike this
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
The GET method is not supported for this route. Supported methods: POST.
Below is my code for all related files.
Admin and Supervisor Middle ware code is same
namespace App\Http\Middleware;
use Closure;
class Admin
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (! Auth::check()) {
return redirect()->route('login');
}
if (Auth::user()->role == 1) {
return redirect()->route('admin');
}
if (Auth::user()->role == 2) {
return redirect()->route('supervisor');
}
}
}
Login Controller
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Auth;
class LoginController extends Controller
{
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo;
public function redirectTo()
{
switch(Auth::user()->role){
case 1: //mapping rolling users
$this->redirectTo = '/admin';
return $this->redirectTo;
break;
case 2:
$this->redirectTo = '/supervisor';
return $this->redirectTo;
break;
default:
$this->redirectTo = '/login';
return $this->redirectTo;
}
// return $next($request);
}
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
}
Routing
Route::get('/', function () {
return view('welcome');});
Auth::routes();
Route::get('/home', 'HomeController@index')->name('home')
Route::POST('/admin', 'AdminController@index')->name('admin'->middleware('admin');
Route::get('/supervisor', 'SupervisorController@index')->name('supervisor')->middleware('supervisor');
Error
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2WYNg1I
via IFTTT
Aucun commentaire:
Enregistrer un commentaire