有没有办法获取经过身份验证的用户 ID 并在 navigation.blade 上使用它?

发布于 2025-01-10 05:46:06 字数 1556 浏览 3 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

囍笑 2025-01-17 05:46:06

感谢@aynber 的回答,我需要做的是:

{{ route('profile', ['id' => Auth::user()->id]) }}

Credits to @aynber to answering, what i needed to do was:

{{ route('profile', ['id' => Auth::user()->id]) }}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文