Laravel RESTful 有两个变量的路线
Laravel RESTful route with two variables
我正在尝试使用两个变量制作 RESTful 路线:
Route::post('trips/{trip_id}/{user_id}', [
'as' => 'trips.apply',
'uses' => 'TripsController@applyForTrip'
]);
控制器:
public function applyForTrip($trip_id, $user_id)
{
dd('I am here! Hooray!');
}
视图中的触发器:
{{ HTML::linkRoute('trips.apply', 'Get on the ride!', [$trip->id, Auth::user()->id], ['class' => 'btn btn-lg btn-success']) }}
所以,当我启动路由时,我得到 MethodNotAllowedHttpException
。所以我想知道,也许我没有正确声明路线,或者其他什么,但对我来说似乎没问题。有什么建议吗?
当您单击锚 link 时,浏览器将向 href
属性中引用的 URL 发送 GET 请求。您已将路由定义为 Laravel 中的 POST 路由,并且由于 Laravel 无法找到与所请求的 URL 匹配的 GET 路由,您得到了不允许的可怕方法异常。
我正在尝试使用两个变量制作 RESTful 路线:
Route::post('trips/{trip_id}/{user_id}', [
'as' => 'trips.apply',
'uses' => 'TripsController@applyForTrip'
]);
控制器:
public function applyForTrip($trip_id, $user_id)
{
dd('I am here! Hooray!');
}
视图中的触发器:
{{ HTML::linkRoute('trips.apply', 'Get on the ride!', [$trip->id, Auth::user()->id], ['class' => 'btn btn-lg btn-success']) }}
所以,当我启动路由时,我得到 MethodNotAllowedHttpException
。所以我想知道,也许我没有正确声明路线,或者其他什么,但对我来说似乎没问题。有什么建议吗?
当您单击锚 link 时,浏览器将向 href
属性中引用的 URL 发送 GET 请求。您已将路由定义为 Laravel 中的 POST 路由,并且由于 Laravel 无法找到与所请求的 URL 匹配的 GET 路由,您得到了不允许的可怕方法异常。