首页 > 解决方案 > 重定向到受中间件 laravel 保护的路由

问题描述

我的仪表板受来宾中间件保护,我想为每个具有 ID 的雇主显示仪表板,但我不知道如何在来宾中间件中获取 ID 我尝试了一些来自 stackoverflow 的解决方案,但返回的 ID 为空

public function handle($request, Closure $next, $guard = null,$id)
{

    $employer=Employer::find($id);
    if (Auth::guard($guard)->check())
        return redirect('/home');
      if(Auth::guard('job_seeker')->check())
      return redirect('job_seeker/profile');

      if(Auth::guard('employer')->check())
      return redirect('employer/dashboard',$employer);

    return $next($request);
}

    //web.php
    Route::get('/dashboard/{id}','Employer\Dashboard_Controller@show_dashboard')->name('employer/dashboard');


class Dashboard_Controller extends Controller
{
    public function __construct(){

        $this->middleware('auth:employer');

    }

    public function show_dashboard($id){
        // $locations=Location::all();
        // $categories=Category::all();
        $employer=Employer::find($id);
        return view('employer.dashboard',compact('employer'));
    }

}

标签: laravelredirectroutesmiddleware

解决方案


推荐阅读