我在控制器(Laravel 5.2)中使用 auth:api 中间件。
class RestfulController extends Controller
{
public function __construct() {
$this->middleware(['api', 'auth:api'], ['except' => ['login'] ]);
}
}
路线:
Route::group(['prefix' => 'api'], function () {
Route::get('/login', ['uses' => 'RestfulController@login', 'as'=>'login']);
Route::get('/list', ['uses' => 'RestfulController@list', 'as'=>'list']);
});
如果请求不包含或包含无效的 api_token 框架重定向到登录页面。相反,我想返回带有错误的 JSON 响应。如何实施?