我在Laravel 5.3中开发。
在查看路线时,我有以下内容:
这表明我的路线是POST。但如果在Postman我输入URL(POST),我会抛出以下错误
最奇怪的是,在我的本地服务器上它工作正常,我在生产服务器上发生了这个错误。
我的代码是:
api.php
Route::group(['middleware' => ['api', 'auth:api']], function() {
require_once 'Routes/Api/ProductRoute.php';
});
路由/路线/原料药/ UserRoute.php
<?php
Route::post('user/authenticate', [
'as' => 'api.user.authenticate',
'uses' => 'Api\UserController@authenticate'
]);
Route::post('user/register', [
'as' => 'api.user.register',
'uses' => 'Api\UserController@register'
]);
/app/Http/Controllers/Api/UserController.php
public function authenticate(Request $request)
{
$credentials = $request->only('email', 'password');
if (Auth::attempt($credentials)) {
$user = Auth::user();
\DB::table('oauth_access_tokens')
->where('user_id', $user->id)
->where('name', $request->platform)
->update(['revoked' => 1]);
$token = $user->createToken($request->platform)->accessToken;
return Controller::apiResponse(1, compact('user', 'token'));
} else{
return Controller::apiResponse(-1);
}
}