有没有办法获取经过身份验证的用户 ID 并在 navigation.blade 上使用它?
我正在使用 Breeze 构建一个新的 Laravel 应用程序。 我想做的是获取经过身份验证的用户 ID,将其重定向到配置文件路径,即:
Route::group([
'prefix' => 'profile',
'as' => 'profile.',
'middleware' => ['auth']
], function () {
Route::get('/{id}', [ProfileController::class, 'show'])->name('profile');
}
);
但是,在导航布局上,如下所示,我无法设法在 :href 上获取它。 我已经尝试过一些方法,例如:
:href="{{ route('profile', [Auth::user()->id]) }}"
:href="{{ route('profile',/([Auth::user()->id])) }}"
但它们似乎都不起作用。
navigation.blade.php 下拉部分:
<x-slot name="content">
<x-dropdown-link :href="route('admin.aprovar')">
{{ __('Aprovações') }}
</x-dropdown-link>
<x-dropdown-link>
{{ __('Perfil') }}
</x-dropdown-link>
<!-- Authentication -->
<form method="POST" action="{{ route('logout') }}">
@csrf
<x-dropdown-link :href="route('logout')"
onclick="event.preventDefault();
this.closest('form').submit();">
{{ __('Log Out') }}
</x-dropdown-link>
</form>
</x-slot>
任何帮助或提示将不胜感激。 感谢您抽出时间!
I'm building a new Laravel app, using Breeze.
What i'm trying to do is get the authenticated user id to redirect it to the profile route, which is:
Route::group([
'prefix' => 'profile',
'as' => 'profile.',
'middleware' => ['auth']
], function () {
Route::get('/{id}', [ProfileController::class, 'show'])->name('profile');
}
);
But, on the layout of navigation, as shown below, i can't manage to get it on the :href.
I already tried some approaches, like:
:href="{{ route('profile', [Auth::user()->id]) }}"
:href="{{ route('profile',/([Auth::user()->id])) }}"
But none of them seems to work.
The navigation.blade.php dropdown part:
<x-slot name="content">
<x-dropdown-link :href="route('admin.aprovar')">
{{ __('Aprovações') }}
</x-dropdown-link>
<x-dropdown-link>
{{ __('Perfil') }}
</x-dropdown-link>
<!-- Authentication -->
<form method="POST" action="{{ route('logout') }}">
@csrf
<x-dropdown-link :href="route('logout')"
onclick="event.preventDefault();
this.closest('form').submit();">
{{ __('Log Out') }}
</x-dropdown-link>
</form>
</x-slot>
Any help or hint would be appreciated.
Thanks for your time!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
感谢@aynber 的回答,我需要做的是:
Credits to @aynber to answering, what i needed to do was: