コード例 #1
0
ファイル: ModelFactory.php プロジェクト: anavel/crud
 /**
  * @param $slug
  * @param null $id
  *
  * @throws \Exception
  *
  * @return Model|null
  */
 public function getBySlug($slug, $id = null)
 {
     $model = null;
     foreach ($this->allConfiguredModels as $modelName => $config) {
         $modelSlug = $this->slugger->slugify($modelName);
         if ($modelSlug === $slug) {
             if (is_array($config)) {
                 $modelNamespace = $config['model'];
             } else {
                 $modelNamespace = $config;
             }
             $model = new Model($config, $this->modelManager->getAbstractionLayer($modelNamespace), $this->relationFactory, $this->fieldFactory, $this->generator, !$this->anavel->hasModule('Anavel\\Uploads\\UploadsModuleProvider'));
             $model->setSlug($modelSlug)->setName($modelName);
             if (is_null($id)) {
                 $model->setInstance($this->modelManager->getModelInstance($modelNamespace));
             } else {
                 $repository = $this->modelManager->getRepository($modelNamespace);
                 $model->setInstance($repository->findByOrFail($repository->getModel()->getKeyName(), $id));
             }
             break;
         }
     }
     if (is_null($model)) {
         throw new FactoryException('Model ' . $slug . ' not found on configuration');
     }
     return $model;
 }
コード例 #2
0
ファイル: FormFieldComposer.php プロジェクト: anavel/crud
 public function compose($view)
 {
     $uploadsModuleIsInstalled = $this->anavel->hasModule('Anavel\\Uploads\\UploadsModuleProvider');
     $view->with(['canTakeFileFromUploads' => $uploadsModuleIsInstalled]);
 }