コード例 #1
0
 public function edit($modelName)
 {
     if (!($model = Config::getModelByClassName($modelName))) {
         throw new \Exception('Model does not exist');
     }
     return view('elegant::admin.modelsettings.edit', ['model' => $model]);
 }
コード例 #2
0
 public function __construct($modelName)
 {
     $modelId = ElegantModel::generateId($modelName);
     if (!($model = Config::getModelById($modelId))) {
         throw new \Exception('Model not found with name ' . $modelName);
     }
     $this->elegantModel = $model;
     parent::__construct($this->elegantModel->getModelInstance());
 }
コード例 #3
0
 /**
  * @param ReflectionClass $class
  * @return ElegantModelInterface|null
  */
 protected function getTranslatedModel(ReflectionClass $class)
 {
     $method = $class->getMethod('getTranslationModelName');
     $translationModelName = $method->invoke($class->newInstance());
     if ($model = Config::getModelByClassName($translationModelName)) {
         return $model;
     } else {
         return null;
     }
 }
コード例 #4
0
 protected function registerEloquentEvents()
 {
     // Flush Elegant cache when anything changes for models registered by Elegant
     Event::listen('eloquent.*', function ($caller) {
         $callerClass = get_class($caller);
         if (!in_array($callerClass, ElegantConfig::getModelsAsClassNames())) {
             return;
         }
         if (in_array(Event::firing(), ['eloquent.saved', 'eloquent.deleted', 'eloquent.updated', 'eloquent.created']) && $this->cacheIsTaggable()) {
             Cache::tags('elegant-' . Support\ElegantModel::normalizeClassName($callerClass))->flush();
         }
     });
 }
コード例 #5
0
 /**
  * @param Model $model
  * @return string
  */
 protected function getRelatedModelAsLink(Model $model)
 {
     $elegantModel = Config::getModelByClassName(get_class($model));
     $modelString = e($elegantModel->getModelAsString($model));
     return "<a href=\"{$elegantModel->getUrl($model)}\">{$modelString}</a>";
 }