/** * Handle the command. */ public function handle() { $grid = $this->builder->getGrid(); $model = $this->builder->getModel(); /* * If the model is already instantiated * then use it as is. */ if (is_object($model)) { $grid->setModel($model); return; } /* * If no model is set, try guessing the * model based on best practices. */ if (!$model) { $parts = explode('\\', str_replace('GridBuilder', 'Model', get_class($this->builder))); unset($parts[count($parts) - 2]); $model = implode('\\', $parts); $this->builder->setModel($model); } /* * If the model is not set then skip it. */ if (!class_exists($model)) { return; } /* * Set the model on the grid! */ $grid->setModel(app($model)); }
/** * Handle the command. */ public function handle() { $grid = $this->builder->getGrid(); $model = $this->builder->getModel(); if (is_string($model) && !class_exists($model)) { return; } if (is_string($model)) { $model = app($model); } if ($model instanceof EntryInterface) { $grid->setStream($model->getStream()); } }
/** * Handle the command. */ public function handle() { $grid = $this->builder->getGrid(); $model = $this->builder->getModel(); /** * If the builder has an entries handler * then call it through the container and * let it load the entries itself. */ if ($handler = $grid->getOption('entries')) { app()->call($handler, ['builder' => $this->builder]); return; } $entries = $grid->getEntries(); /** * If the entries have already been set on the * grid then return. Nothing to do here. * * If the model is not set then they need * to load the grid entries themselves. */ if (!$entries->isEmpty() || !$model) { return; } /** * Resolve the model out of the container. */ $repository = $grid->getRepository(); /** * If the repository is an instance of * GridRepositoryInterface use it. */ if ($repository instanceof GridRepositoryInterface) { $grid->setEntries($repository->get($this->builder)); } }