laravel - 重定向到受中间件 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'));
}
}
解决方案
推荐阅读
- javascript - 需要拆分字符串逗号分隔,包括圆括号
- mysql - 如何禁用 MySQL histignore?
- php - 从显示每个用户记录的数据库中检索数据 - Laravel
- javascript - 根据工作日数获取工作日数组
- xml - XSD 将复杂元素定义为强制但所有子元素都是可选的是否有效?
- java - 既然不推荐使用 android 命令,我应该如何在没有 android studio 的情况下创建 android 应用程序
- sql - 将行插入另一个数据库时如何在一个数据库中获取信息?
- java - CodenameOne BrowserComponent 不适用于 UWP 构建
- apache-spark - Apache Spark 中的最小单位是块吗?
- javascript - 使用 splice() 根据索引从数组中删除值