hasHeader('access-token')) { return response()->json(['status' => 'error', 'status_code' => 401, 'message' => 'Access token not provided'], 401); } // Retrieve the token from the custom access-token header $token = $request->header('access-token'); try { // Attempt to authenticate the user based on the token $user = JWTAuth::setToken($token)->authenticate(); // Check if the user is of restaurant type if (!$user ||$user->principal_type_xid != 4) { return response()->json(['status' => 'error', 'status_code' => 401, 'message' => 'Unauthorized access'], 401); } Session::flash('RestToken', $token); } catch (JWTException $e) { return response()->json(['status' => 'error', 'status_code' => 401, 'message' => 'Invalid token'], 401); } return $next($request); } }