【发布时间】:2017-07-05 22:42:19
【问题描述】:
我的 laravel 应用程序是一个社交媒体网站。这是访问另一个 laravel 用户个人资料的路线
Route::get('/dashboard/{id}', [
'uses' => 'UserController@getProfile',
'as' => 'profile.index',
'middleware' => 'auth'
]);
它工作得很好。但是,我发现了一个错误,当我在路由中输入 Auth 用户的 ID 时,我会被带到同一个页面,然后我可以将自己添加为朋友,我不希望这种情况发生。如果我正在访问自己的个人资料,我宁愿回到主屏幕。
这是控制器:
public function getProfile($id)
{
if(Auth::user() === $id)
redirect('dashboard');
$user = User::where('id', $id)->first();
$posts = Post::where("dash_id", "=", $user->id)->latest()->paginate(3);
$photos = Photo::paginate(6);
return view('profile.index',compact('user','posts', 'photos'));
}
我试图让它重定向到“仪表板”而不是“profile.index”,如果它是 Auth 用户的页面,而不是像普通的非身份验证配置文件那样拉起,但似乎无法得到它去工作。关于如何修复这个小错误的任何想法?
【问题讨论】:
标签: php laravel authentication routes