【发布时间】:2020-01-22 22:36:36
【问题描述】:
我有一个名为profile.blade.php 的html 页面,其中包含一个锚标记:
<a href="{{ route('profile', $user->id) }}">{{$user->name}}</a>
我有这样的路线:
Route::get('/profile/{id}', 'ProfilesController@index')->name('profile');
我有一个ProfilesController,其中 index 方法返回一个拥有该配置文件的用户:
public function index()
{
$userId = //somehow get the data sent from the anchor tag
$user = $this->usersService->getProfileOwner($userId);
return view("profile", [
'user' => $user ?? []
]);
}
如何更改此代码,例如当 id 为 1 的用户访问 id 为 2 的用户的个人资料时,索引函数会将用户 2 的详细信息返回到blade 模板?
【问题讨论】:
-
你试过
request()->id吗?