Allocation::class, 'database' => Database::class, 'egg' => Egg::class, 'location' => Location::class, 'nest' => Nest::class, 'node' => Node::class, 'server' => Server::class, ]; /** * Perform substitution of route parameters without triggering * a 404 error if a model is not found. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { $route = $request->route(); foreach (self::$mappings as $key => $model) { $this->router->model($key, $model); } $this->router->substituteBindings($route); // Attempt to resolve bindings for this route. If one of the models // cannot be resolved do not immediately return a 404 error. Set a request // attribute that can be checked in the base API request class to only // trigger a 404 after validating that the API key making the request is valid // and even has permission to access the requested resource. try { $this->router->substituteImplicitBindings($route); } catch (ModelNotFoundException $exception) { $request->attributes->set('is_missing_model', true); } return $next($request); } /** * Return the registered mappings. * * @return array */ public static function getMappings() { return self::$mappings; } }