我正在使用Laravel 5.6,并且我在routes / api.php中的现有路由上获得HTTP404响应,我将其定义如下:
Route::middleware('auth:api')->post('/account/plan', 'Account\BillingController@updatePlan');
Route::middleware('auth:api')->put('/account/plan', 'Account\BillingController@unsubscribe');
Route::middleware('auth:api')->patch('/account/plan', 'Account\BillingController@resubscribe');
当我在这些路由上使用axios.post()并包含_method参数时,我在PUT和PATCH路由上得到404响应。我还测试了axios.put()/ axios.patch()代替使用post(),有或没有_method参数的inclsion。我还确认这些是由工匠路线正确表示的:列表:
| | POST | api/account/plan | | App\Http\Controllers\Account\BillingController@updatePlan | api,auth:api |
| | PUT | api/account/plan | | App\Http\Controllers\Account\BillingController@unsubscribe | api,auth:api |
| | PATCH | api/account/plan | | App\Http\Controllers\Account\BillingController@resubscribe | api,auth:api |
Axios呼叫示例:
axios.post(url,{_method:"PUT",confirm:"unsubscribe"})
.then(response => callback(response.data))
.catch(error => console.log(error))
当我按如下方式定义这些相同的路线时,它们都按预期工作:
Route::middleware('auth:api')->post('/account/plan', 'Account\BillingController@updatePlan');
Route::middleware('auth:api')->post('/account/unsubscribe', 'Account\BillingController@unsubscribe');
Route::middleware('auth:api')->post('/account/resubscribe', 'Account\BillingController@resubscribe');
我能够通过其他路由上的请求方法分离端点我不确定为什么这些会产生问题。有人可以解释为什么我得到404回复以及如何避免它们?
答案 0 :(得分:3)
因为看起来你做得很好,也许通过遵循laravel更严格的约定来定义路线你不会遇到问题?试试这样:
.btn::after