Create a Model Lang file from config array
@param string $model the model name in lowercase
342358
public function createlang($model) {
        $this->console->line("Preparing model attributes");
        $bar = $this->console->output->createProgressBar(5);
        $options = $this->console->options('path');
        if ($options['path'] != "") {
            $path = $options['path'];
        } else {
            $path = "lang/vendor/crudgenerator/" . config("app.locale");
        }
        $path = str_replace("//", "/", str_replace(["\\", " "], ["/", ""], $path));
        $filename = str_finish(strtolower($model), ".php");
        $bar->advance();
        $this->console->line("Loading config array for {$model}");
        $config = CrudGenerator::getConfig($model, false);
        $bar->advance();
        $this->console->info("Config loaded!");
        //$this->console->line(print_r($config, true));
        $bar->advance();
        $this->console->line("Saving Lang file for {$model} in {$path} with filename '{$filename}'");
        if (CrudGenerator::saveResource("sirgrimorum::templates.lang", false, resource_path($path), $filename, $config)) {
            $this->console->info("Model Lang file saved!");
        } else {
            $this->console->error("Something went wrong and the model lang file could not be saved");
        }
        $bar->advance();
        $confirm = $this->console->choice("Do you wisth to create a Lang File for the model in es?", ['yes', 'no'], 0);
        if ($confirm == 'yes') {
            $path = "lang/vendor/crudgenerator/es";
            $filename = str_finish(strtolower($model), ".php");
            $this->console->line("Saving Lang file for {$model} in {$path} with filename '{$filename}'");
            if (CrudGenerator::saveResource("sirgrimorum::templates.langes", false, resource_path($path), $filename, $config)) {
                $this->console->info("Model Lang file saved!");
                $bar->finish();
            } else {
                $this->console->error("Something went wrong and the model lang file could not be saved");
                $bar->finish();
            }
        }
        $bar->finish();
    }
525868
public function saved($model)
    {
        $translationRepository = \App::make(TranslationRepository::class);
        $cacheRepository       = \App::make('translation.cache.repository');
        foreach ($model->translatableAttributes() as $attribute) {
            // If the value of the translatable attribute has changed:
            if ($model->isDirty($attribute)) {
                $translationRepository->updateDefaultByCode($model->translationCodeFor($attribute), $model->getRawAttribute($attribute));
            }
        }
        $cacheRepository->flush(config('app.locale'), 'translatable', '*');
    }
1193436
public function creating(Model $model)
    {
        // we only create this once
        if (Schema::hasColumn($model->getTable(), 'hashslug') && is_null($model->hashslug)) {
            $timestamp       = time() + $model->count() + 1;
            $str_slug_fqcn   = str_slug_fqcn($model);
            $model->hashslug = hashids($str_slug_fqcn)->encode($timestamp);
        }
    }
1097777
public function toArray(Model $model)
    {
        // start with the base representation of the model
        if (method_exists($model, 'withoutArrayHook')) {
            $model->withoutArrayHook();
        }
        $result = $model->toArray();

        // apply namespacing to excluded properties
        $namedExc = [];
        foreach ($this->exclude as $k) {
            array_set($namedExc, $k, true);
        }

        // apply namespacing to included properties
        $namedInc = [];
        foreach ($this->include as $k) {
            array_set($namedInc, $k, true);
        }

        // apply namespacing to expanded properties
        $namedExp = [];
        foreach ($this->expand as $k) {
            array_set($namedExp, $k, true);
        }

        // remove excluded properties
        foreach (array_keys($result) as $k) {
            if (isset($namedExc[$k]) && !is_array($namedExc[$k])) {
                unset($result[$k]);
            }
        }

        // add included properties
        foreach (array_keys($namedInc) as $k) {
            if (!isset($result[$k]) && isset($namedInc[$k])) {
                $result[$k] = $model->$k;
                if ($result[$k] instanceof Model) {
                    $subExc = array_value($namedExc, $k);
                    $subInc = array_value($namedInc, $k);
                    $subExp = array_value($namedExp, $k);

                    // convert exclude, include, and expand into dot notation
                    // then take the keys for a flattened dot notation
                    $flatExc = is_array($subExc) ? array_keys(array_dot($subExc)) : [];
                    $flatInc = is_array($subInc) ? array_keys(array_dot($subInc)) : [];
                    $flatExp = is_array($subExp) ? array_keys(array_dot($subExp)) : [];

                    $serializer = new self($this->request);
                    $serializer->setExclude($flatExc)
                        ->setInclude($flatInc)
                        ->setExpand($flatExp);

                    $result[$k] = $serializer->toArray($result[$k]);
                }
            }
        }

        // expand any relational model properties
        $result = $this->expand($model, $result, $namedExc, $namedInc, $namedExp);

        // apply hooks, if available
        if (method_exists($model, 'toArrayHook')) {
            $model->toArrayHook($result, $namedExc, $namedInc, $namedExp);
        }

        // order the properties array by name for consistency
        // since it is constructed in a random order
        ksort($result);

        return $result;
    }
1031363
private function generateModel($model){
        if(is_object($model))
            Session::set(md5(Request::getArea().Request::getController().Request::getAction()), base64_encode(get_class($model)));
    }
565181
public function setModel($model)
    {
        if(!($model instanceof ModelInterface))
        {
            if(is_string($model) && strpos($model, '.') === false )
            {
                // Model names are always plural
                if(StringInflector::isSingular($model)) {
                    $model = StringInflector::pluralize($model);
                }

                $identifier         = $this->getIdentifier()->toArray();
                $identifier['path'] = array('model');
                $identifier['name'] = $model;

                $identifier = $this->getIdentifier($identifier);
            }
            else $identifier = $this->getIdentifier($model);

            $model = $identifier;
        }

        $this->_model = $model;

        return $this->_model;
    }
1154634
public function createInHierarchy( $model ) {

		$table = $this->getModelTable();

		// Manage Hierarchy

		// Top Level Model
		if( $model->parentId <= 0 ) {

			unset( $model->parentId );

			$model->lValue	= CoreGlobal::HIERARCHY_VALUE_L;
			$model->rValue	= CoreGlobal::HIERARCHY_VALUE_R;

			// Create Model
			$model->save();

			// Update Root Id
			$model			= $this->getById( $model->id );
			$model->rootId	= $model->id;

			$model->update();
		}
		// Child Model
		else {

			$parentModel = $this->getById( $model->parentId );

			// Top Level Parent
			if( !$parentModel->hasParent() ) {

				// Add child at end
				$model->lValue			= $parentModel->rValue;
				$model->rValue			= $parentModel->rValue + 1;
				$parentModel->rValue	= $parentModel->rValue + 2;
				$model->rootId			= $parentModel->rootId;

				// Update Parent
				$parentModel->update();
			}
			// Lower Level Parent
			else {

				$children	= $parentModel->children;
				$parentRoot	= $parentModel->rootId;

				// Has Children, add as last child
				if( count( $children ) > 0 ) {

					$incCharger	= $parentModel->rValue - 1;
				}
				// No Children
				else {

					$incCharger	= $parentModel->lValue;
				}

				// Update left and right values
				Yii::$app->db->createCommand( "UPDATE $table set lValue = lValue + 2 WHERE rootId = $parentRoot and lValue > $incCharger" )->execute();
				Yii::$app->db->createCommand( "UPDATE $table set rValue = rValue + 2 WHERE rootId = $parentRoot and rValue > $incCharger" )->execute();

				// Configure child
				$model->lValue	= $parentModel->rValue;
				$model->rValue	= $parentModel->rValue + 1;
				$model->rootId	= $parentRoot;
			}

			// Create Model
			$model->save();
		}

		return $model;
	}
730099
public function setModel($model)
    {
        if (is_string($model)) {
            $model = $this->factory()->get($model);
        }

        if (!$model instanceof ModelInterface) {
            throw new InvalidArgumentException(
                sprintf(
                    'The model must be an instance of "%s"',
                    ModelInterface::class
                )
            );
        }

        $this->model = $model;

        $this->setSource($model->source());

        return $this;
    }
1223527
public static function createTagFromModel(Model $model)
    {
        return new Tag((string) $model->id, $model->name, $model->row());
    }
694594
public function saveTranslations(
            \Illuminate\Database\Eloquent\Model $model, 
            array $translations){
        
        if(empty($translations))
            throw new MissingTranslationsException;
        
        if(empty($this->translation_name))
            throw new MissingTranslationNameException;
        
        return $model->{$this->translation_name}()->saveMany($translations);
    }
995618
public function process(Model $model)
    {
        $data = $model->getData();

        // Check if this is a possible callback.
        // We are not going to analyse this further, because modern systems
        // do not use these anymore.
        if (function_exists($data) === true) {
            $model->setIsCallback(true);
        }

        // Checking the encoding.
        $encoding = $this->pool->encodingService->mbDetectEncoding($data);
        if ($encoding === false) {
            // Looks like we have a mixed encoded string.
            // We need to tell the dev!
            $length = $this->pool->encodingService->mbStrLen($data);
            $strlen = 'broken encoding ' . $length;
            $model->addToJson(static::META_ENCODING, 'broken');
        } else {
            // Normal encoding, nothing special here.
            $length = $strlen = $this->pool->encodingService->mbStrLen($data, $encoding);
        }

        if ($length > 20) {
            // Getting mime type from the string.
            // With larger strings, there is a good chance that there is
            // something interesting in there.
            $model->addToJson(static::META_MIME_TYPE, $this->bufferInfo->buffer($data));
        }

        // Check, if we are handling large string, and if we need to use a
        // preview (which we call "extra").
        // We also need to check for linebreaks, because the preview can not
        // display those.
        if ($length > 50 || strstr($data, PHP_EOL) !== false) {
            $cut = $this->pool->encodingService->encodeString(
                $this->pool->encodingService->mbSubStr($data, 0, 50)
            ) . static::UNKNOWN_VALUE;

            $data = $this->pool->encodingService->encodeString($data);

            $model->setHasExtra(true)
                ->setNormal($cut)
                ->setData($data);
        } else {
            $model->setNormal($this->pool->encodingService->encodeString($data));
        }

        return $this->pool->render->renderSingleChild(
            $model->setType(static::TYPE_STRING . $strlen)
                ->addToJson(static::META_LENGTH, $length)
        );
    }
1299425
protected function parseModel($model)
    {
        if (isset($this->alias[$model])) {
            $model = $this->alias[$model];
        }

        if (false === strpos($model, '\\')) {
            $path = explode('\\', get_class($this->parent));
            array_pop($path);
            array_push($path, Db::parseName($model, 1));
            $model = implode('\\', $path);
        }

        return $model;
    }
673948
public function create( $model, $config = [] ) {

		$modelClass = static::$modelClass;

		// Default Private
		if( !isset( $model->visibility ) ) {

			$model->visibility = $modelClass::VISIBILITY_PRIVATE;
		}

		// Default New
		if( !isset( $model->status ) ) {

			$model->status = $modelClass::STATUS_NEW;
		}

		return parent::create( $model, $config );
	}
1272181
protected function processSingle(array $data, $lang, $model)
    {
        is_null($view    = array_get($data, 'templates.' . $lang->code)) ? $view    = array_get($data, 'templates.' . $lang->code) : null;
        $content = '';
        if (is_null($view)) {
            $content = app($data['classname'])->render();
        } else {
            $path = view($view)->getPath();
            if (!file_exists($path)) {
                throw new Exception(trans('antares/notifications::messages.notification_view_not_exists', ['path' => $path]));
            }
            $content = file_get_contents($path);
        }

        return $model->contents()->save($model->contents()->getModel()->newInstance([
                            'notification_id' => $model->id,
                            'lang_id'         => $lang->id,
                            'title'           => array_get($data, 'title'),
                            'subject'         => array_get($data, 'subject'),
                            'content'         => $content
        ]));
    }
90496
protected function parseModel($model)
    {
        if (false === strpos($model, '\\')) {
            $path = explode('\\', static::class);
            array_pop($path);
            array_push($path, Db::parseName($model, 1));
            $model = implode('\\', $path);
        }

        return $model;
    }
405951
public static function getSlug($model)
    {
        $i18nModels = $model->i18n;
        $slugs = [];
        foreach ($i18nModels as $i18nModel) {
            if (empty($i18nModel->body)) continue; // skip languages for news without body
            $slugs[$i18nModel->lang_code] = $i18nModel->slug;
        }

        //$langs = array_keys(LangHelper::activeLanguages()); // better use as container-module's member:
        $module = Module::getModuleByClassname(Module::className());
        $langHelper = $module->langHelper;
        $langs = array_keys($langHelper::activeLanguages());
        $slug = '';
        foreach ($langs as $lang) {
            if (!empty($slugs[$lang])) {
                $slug = $slugs[$lang];
                break;
            }
        }
        if (strlen($slug) > static::$slugMaxLen) {
            $slug = substr($slug, 0, static::$slugMaxLen);
        }
        $slug = trim($slug, '-');
        return $slug;
    }
705797
public static function load($model = false) {

        $path = DOC_ROOT . Config::get('paths', 'modules');

        if ($model && File::isFile($path . $model . '.php')) {

            $array = explode('/', $model);
            $modelName = end($array);
          
            require $path . $model . '.php';

            return new $modelName();
        }

        return false;
    }