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