[英]error 404 page not found (laravel 5.8)(like button route)
I want to add like button to my posts but when I'm clicking on button getting a 404 error. 我想在帖子中添加点赞按钮,但是当我点击按钮时出现404错误。
this is my view 这是我的看法
<form action="{{route('user.like', ['postId' => $post->id, 'userId' => Auth::user()->id])}}" method="POST">
@csrf
<input class="btn btn-success" type="submit" role="button" value="like"/>
</form>
the route 路线
Route::post('/user{userId}/post{postId}/like',[
'uses' => 'postController@like',
'as' => 'user.like'
]);
and this is my controller 这是我的控制器
public function like($postId, $userId){
$user = User::findOrFail($userId);
$user->votedPosts()->attach($postId);
return redirect()->back();
}
I really have no idea why im getting error 404. 我真的不知道为什么我会收到错误404。
while you try to bind variable in your route it written in this way {userId}
not userId{userId}
当您尝试在路由中绑定变量时,它是通过
{userId}
而不是userId{userId}
编写的
so it will be like this 所以会是这样
Route::post('like/{postId}/{userId}',[
'uses' => 'postController@like',
'as' => 'user.like' ]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.