当我在另一个类中扩展 ApiBaseController 时,拒绝响应令牌不起作用。即使我输入了错误的 app-token,但仍然在另一堂课上做出回应。
class ApiBaseController extends Controller
{
protected $user;
public function __construct()
{
if (request()->header('app-token') != 'ofdsafalkhguddskjafl01JhBF9mGx2jay'){
return response()->json([
'success'=>false,
'status'=>'401',
'message'=>'Token Denied !',
'response'=>[
'total'=>0,
'data'=>[]
]
]);
}
else{
$this->user = Auth::guard('api')->user();
}
}
}
即使我输入了错误的应用令牌,该课程仍然有效
class AttendeesApiController extends ApiBaseController
{
public function index(Request $request)
{
return Attendee::scope($this->account_id)->paginate($request->get('per_page', 25));
}
}
我想确保当 app-token 出错时会给出Token Denied !响应请给我一些建议
慕尼黑的夜晚无繁华
aluckdog