使用LARAVEL 6中的前端刀片设置具有登录用户ID的URL

问题描述 投票:0回答:2

您好,我正在尝试从刀片服务器(welcome.blade.php)设置URL(href)以登录用户的用户个人资料。

我的网址必须是这样-> sample.com/profile/24

那里,有24个已登录用户的用户ID

<a href="{{URL('/profile/{{ Auth::user()->id }}')}}" class="btn btn-primary">profile</a>

但是当我运行代码时,它给了我以下异常,

Facade \ Ignition \ Exceptions \ ViewException语法错误,意外的'}',期望的是')'

php laravel authentication href laravel-6
2个回答
0
投票

无需在{{}}内再次使用{{}}

更改

<a href="{{URL('/profile/{{ Auth::user()->id }}')}}" class="btn btn-primary">profile</a>

to

<a href="{{URL('/profile/'.Auth::user()->id)}}" class="btn btn-primary">profile</a>

0
投票

或者,如果您有设置路线来显示用户个人资料,也可以这样做

<a href="{{route('users.show', Auth::user()->id)}}" class="btn btn-primary">profile</a>

那么您的路线将是这样的

Route::get('profile/{user}', 'UsersController@show')->name('users.show');
© www.soinside.com 2019 - 2024. All rights reserved.