我正在使用Laravel API身份验证功能并使用令牌。 (如此处所述: https://laravel.com/docs/5.8/api-authentication#protecting-routes)
我正在使用Postman运行一些测试,它正常工作。当我尝试访问没有有效令牌的路由时,我看到响应是我的应用程序(登录页面的)HTML。我该如何返回未经授权
消息而不是完整的登录页面?我需要创建自定义中间件吗?
控制器
class ExampleController extends Controller
{
public function __construct()
{
$this->middleware('auth:api');
}
public function show(Request $request) {
return response()->json($request->user()->name);
}
}
X-Requested-With:XMLHttpRequest
,谢谢! - user3253002