在 laravel breeze 项目中,可通过 `auth::user()->id` 获取当前认证用户的 id,并在 `navigation.blade.php` 中安全地传递给 `route()` 辅助函数,从而生成指向 `/profile/{id}` 的正确链接。
要在导航下拉菜单中为“Perfil”(个人资料)添加跳转至当前用户专属档案页的链接,关键在于正确构造命名路由的参数。你的路由定义为:
Route::get('/{id}', [ProfileController::class, 'show'])->name('profile');
这表示该路由接受一个必需的 id 参数,且命名是 profile(注意:不是 profile.profile 或其他嵌套名)。因此,在 Blade 模板中调用 route() 时,必须以关联数组形式显式指定键名,即 [‘id’ => Auth::user()->id]。
✅ 正确写法(推荐):
Auth::user()->id])">
{{ __('Perfil') }}
⚠️ 常见错误与说明: