我想在登录后显示 domen url 用户 id,例如 domen/specialist/id。已经是第 2 天了,它还没有被接受。也许我做错了什么请帮忙。这是我的 web.php 代码 // Front End Routes Route::group([ 'namespace' => 'landing', 'middleware' => 'groups', ], function (){ Route::get('/', 'PagesController@index')->name('landing.index'); Route::get('/specialist/{id}', 'SpecialistDashboardController@dashboard')- >name('frontend.specialist.dashboard'); Route::get('/logout', '\App\Http\Controllers\Auth\LoginController@logout');});专家仪表板控制器代码class SpecialistDashboardController extends Controller{ public function dashboard($id){ $id = Auth::user()->id; return view('Frontend.specialists.dashboard.index'); } public function profile_settings(){ return view('Frontend.specialists.profile_settings.index'); }}群组中间件 public function handle($request, Closure $next) { // ADMIN = 5 if (\Auth::check() && Auth::user()->groups == 5){ return $next($request); } // PATIENTS = 1 elseif(\Auth::check() && Auth::user()->groups == 1){ return redirect()->route('landing.index'); } // SPECIALISTS = 3 elseif (\Auth::check() && Auth::user()->groups == 3){ return redirect()->route('frontend.specialist.dashboard'); } }错误消息:缺少 [Route: frontend.specialist.dashboard] [URI: specialist/{id}] 所需的参数。
1 回答
守着一只汪
TA贡献1872条经验 获得超3个赞
您的frontend.specialist.dashboard路线需要一个id参数,但您在重定向时没有提供任何参数。同时查看您的SpecialistDashboardController,$id可以省略,因为您正在用 覆盖它Auth::id()。
尝试这样做:
# remove the {id} param
Route::get('/specialist', 'SpecialistDashboardController@dashboard')-
>name('frontend.specialist.dashboard');
class SpecialistDashboardController extends Controller
{
...
public function dashboard(){ // remove the $id param
$id = Auth::user()->id;
return view('Frontend.specialists.dashboard.index');
}
...
}
但是如果在任何情况下你都需要 id 参数,你可以通过做重定向来提供它的值
return redirect()->route('frontend.specialist.dashboard', ['id' => $id]);
- 1 回答
- 0 关注
- 82 浏览
添加回答
举报
0/150
提交
取消