auth = $auth; } /** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @param bool $required * * @return mixed */ public function handle(Request $request, Closure $next, $required = false) { if ($this->auth->guest()) { if ($apiToken = $request->header('X-Cachet-Token')) { try { $this->auth->onceUsingId(User::findByApiToken($apiToken)->id); } catch (ModelNotFoundException $e) { if ($required) { throw new HttpException(401); } } } elseif ($required) { throw new HttpException(401); } } return $next($request); } }