When i install multi-auth in laravel but routing issue occur.
I'm edit in web.php when address bar write in ,
localhost/projectname/admin but error occur - page not found but i passed specific address like this
localhost/projectname/admin/login after that page open BUT this not good. can you possible i'm only pass
localhost/projectname/admin after that page(view) open ?
Middleware
protected $routeMiddleware = [ 'admin' => \App\Http\Middleware\RedirectIfNotAdmin::class, 'admin.guest' => \App\Http\Middleware\RedirectIfAdmin::class, 'auth' => \Illuminate\Auth\Middleware\Authenticate::class, 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, ]; Middleware RedirectifNotAdmin.php controller
<?php namespace App\Http\Middleware; use Closure; use Illuminate\Support\Facades\Auth; class RedirectIfNotAdmin { /** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @param string|null $guard * @return mixed */ public function handle($request, Closure $next, $guard = 'admin') { if (!Auth::guard($guard)->check()) { return redirect('admin/login'); } return $next($request); } } my routes
Route::get('/admin', 'AdminController@index'); Controller file AdminController
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; class HomeController extends Controller { /** * Create a new controller instance. * * @return void */ public function __construct() { $this->middleware('auth:admin'); } /** * Show the application dashboard. * * @return \Illuminate\Http\Response */ public function index() { return view('admin'); } }
Route::get('/admin', 'AdminController@index')->middleware(['auth:admin'])public function handle($request, Closure $next, $guard = 'admin') { dd('auth middleware') if (!Auth::guard($guard)->check()) { return redirect('admin/login'); } return $next($request); }