Example #1
0
 /**
  * Setup the defined modules.
  * @return void
  */
 public function boot()
 {
     foreach ($this->modules as $class => $module) {
         $module->boot();
         $this->models = array_merge($module->models, $this->models);
     }
     // Map the routes.
     $this->app->call([$this, 'map']);
 }
Example #2
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle(Request $request, Closure $next)
 {
     $modelIndex = Application::context(Application::CXT_API) ? 3 : 2;
     $idIndex = Application::context(Application::CXT_API) ? $modelIndex + 1 : $modelIndex + 2;
     // Check for the model slug. Throw 404 if not found.
     $modelSegment = $request->segment($modelIndex);
     $idSegment = $request->segment($idIndex);
     $blueprint = ModelBlueprint::slug($modelSegment);
     if (!$blueprint) {
         $message = "Class for '{$modelSegment}' does not exist";
         return Application::context(Application::CXT_API) ? RESTResponse::failed($message, 404) : response($message, 404);
     }
     $class = $blueprint->getClass();
     // Check if the model ID was given.
     if ($idSegment) {
         $model = $class::find($idSegment);
         if (!$model) {
             $message = "Model '{$modelSegment}/{$idSegment}' does not exist";
             return Application::context(Application::CXT_API) ? RESTResponse::failed($message, 404) : response($message, 404);
         }
         $request->Model = $model;
         return $next($request);
     }
     // Otherwise, return the static model class.
     $request->Model = new $class();
     return $next($request);
 }
 /**
  * Set up some early environment variables.
  * @param Request $request
  */
 public function boot_environment(Request $request)
 {
     $request->context = Application::context();
 }