Make sure a model has been defined for this restful resource

@return void
979370
public function validateImplementation()
	{
		$required = [
			'model'         => ' does not implement a model definition.',
			'resource_path' => ' does not implement a resource path definition.',
		];

		foreach ($required as $implementation => $message) {
			if (! isset($this->{$implementation})) {
				throw new \InvalidArgumentException(static::class . $message);
			}
		}
	}
328975
public function prepareModelCrudeSetup()
    {
        $crudeName = $this->getCalledClassName();
        $modelAttr = array_merge(['id'], $this->model->getFillable(), ['created_at']);

        foreach ($modelAttr as $attr)
            $this->scope[$attr] = $this->model->getTable() . '.' . $attr;

        $this->crudeSetup = new CrudeSetup($crudeName, $modelAttr);

        if ($this->cannotUpdate())
            $this->crudeSetup->lockEditOption();

        if ($this->cannotStore('check with permission'))
            $this->crudeSetup->lockAddOption();

        if ($this->cannotDelete())
            $this->crudeSetup->lockDeleteOption();

        if ($this->cannotOrder())
            $this->crudeSetup->lockOrderOption();

        $this->crudeSetup->setFilters(['id']);

        return $this->crudeSetup;
    }
448977
protected function prepareModelOverrides()
    {
        $this->overrides = $this->getOverrideConfigForModel($this->moduleId);

        // determine name to use, handle pluralization and check database table override
        if (array_key_exists('name', $this->overrides)) {

            $name = $this->overrides['name'];

        } else {

            $name = array_get($this->module, 'prefixed_name') ?: $this->model['name'];

            if (config('pxlcms.generator.models.model_name.singularize_model_names')) {

                if ($this->context->dutchMode) {
                    $name = $this->dutchSingularize($name);
                } else {
                    $name = str_singular($name);
                }
            }
        }

        // make sure we force set a table name if it does not follow convention
        $tableOverride = null;

        if (str_plural($this->normalizeDb($name)) != $this->normalizeDb($this->module['name'])) {

            $tableOverride = $this->getModuleTablePrefix($this->moduleId)
                           . $this->normalizeDb($this->module['name']);
        }

        // force listified?
        $listified = array_key_exists('listify', $this->overrides)
                   ?    (bool) $this->overrides['listify']
                   :    $this->model['is_listified'];


        // override hidden attributes?
        $this->overrideHidden = [];

        if (    ! is_null(array_get($this->overrides, 'attributes.hidden'))
            &&  ! array_get($this->overrides, 'attributes.hidden-empty')
        ) {
            $this->overrideHidden = array_get($this->overrides, 'attributes.hidden');

            if ( ! is_array($this->overrideHidden)) $this->overrideHidden = [ (string) $this->overrideHidden ];
        }


        // apply overrides to model data
        $this->model['name']         = $name;
        $this->model['table']        = $tableOverride;
        $this->model['is_listified'] = $listified;
        $this->model['hidden']       = $this->overrideHidden;
        $this->model['casts']        = array_get($this->overrides, 'attributes.casts', []);
    }
725120
public function bootEloquent()
    {
        Eloquent::setConnectionResolver($this->manager);

        // If we have an event dispatcher instance, we will go ahead and register it
        // with the Eloquent ORM, allowing for model callbacks while creating and
        // updating "model" instances; however, it is not necessary to operate.
        if ($dispatcher = $this->getEventDispatcher()) {
            Eloquent::setEventDispatcher($dispatcher);
        }
    }
599277
private function _checkModelProperty()
    {
        if (!$this->model) {
            if (Lang::has('resource-composer.propertynotset')) {
                $message = trans('resource-composer.propertynotset', ['property' => '$model']);
            } else {
                $message = '$model property must be set.';
            }

            throw new ResourceComposerException($message);
        }
    }
790785
protected function checkModels()
    {
        $models = func_get_args();
        //
        foreach ($models as $model) {
            if (!class_exists($model)) {
                $this->ModelNotFound($model);
            }
        }
    }
5434
protected function registerEloquentModels()
    {
        $files = $this->app['files']->files(storage_path('framework/entities'));
        
        foreach ($files as $file) {
            if ($this->app['files']->extension($file) == '') {
                require_once $file;
            }
        }
    }
506012
protected function ensureNotEmpty() {
        $this->currentInstance = 0;
        while ($this->resourceIterator->valid() && !$this->load($this->resourceIterator->current(), 0)) {
            $this->resourceIterator->next();
        }
    }
1331204
public function retrieveModel()
    {
        if ($this->model->persisted()) {
            return;
        }

        $modelClass = $this->modelClass;
        $this->model = $modelClass::find($this->modelId);

        if (!$this->model) {
            throw $this->modelNotFoundError();
        }
    }
345313
protected function prepareForValidation(): void
    {
        $data = $this->all();

        $member = $this->route('member') ?? app('cortex.auth.member');
        $country = $data['country_code'] ?? null;
        $twoFactor = $member->getTwoFactor();

        if ($member->exists && empty($data['password'])) {
            unset($data['password'], $data['password_confirmation']);
        }

        // Set abilities
        if (! empty($data['abilities'])) {
            if ($this->user($this->route('guard'))->can('grant', \Cortex\Auth\Models\Ability::class)) {
                $abilities = array_map('intval', $this->get('abilities', []));
                $data['abilities'] = $this->user($this->route('guard'))->isA('superadmin') ? $abilities
                    : $this->user($this->route('guard'))->getAbilities()->pluck('id')->intersect($abilities)->toArray();
            } else {
                unset($data['abilities']);
            }
        }

        // Set roles
        if (! empty($data['roles'])) {
            if ($data['roles'] && $this->user($this->route('guard'))->can('assign', \Cortex\Auth\Models\Role::class)) {
                $roles = array_map('intval', $this->get('roles', []));
                $data['roles'] = $this->user($this->route('guard'))->isA('superadmin') ? $roles
                    : $this->user($this->route('guard'))->roles->pluck('id')->intersect($roles)->toArray();
            } else {
                unset($data['roles']);
            }
        }

        if ($twoFactor && (isset($data['phone_verified_at']) || $country !== $member->country_code)) {
            array_set($twoFactor, 'phone.enabled', false);
            $data['two_factor'] = $twoFactor;
        }

        $this->replace($data);
    }
433110
public final function loadModel(): void
    {
        if ($this->model != null) {
            return;
        }

        $file = sprintf('%s/app/service/%s/model/model.php', APP_DIR, $this->name);
        if (!file_exists($file)) {
            throw new ServiceException("Cannot load {$this->name} model, model file app/service/{$this->name}".
                "/model/model.php not found");
        }

        // FooService => FooModel
        $class = sprintf('froq\\app\\database\\%sModel', substr($this->name, 0, -strlen(self::SERVICE_NAME_SUFFIX)));
        if (!class_exists($class)) {
            throw new ServiceException("Cannot load {$this->name} model, model class {$class} not found");
        }

        $this->model = new $class($this);
    }
1097279
public function validateModelClass()
    {
        if ($this->isReservedKeyword($this->modelClass)) {
            $this->addError('modelClass', 'Class name cannot be a reserved PHP keyword.');
        }
        if (substr($this->tableName, -1) !== '*' && $this->modelClass == '') {
            $this->addError('modelClass', 'Model Class cannot be blank if table name does not end with asterisk.');
        }
    }
1253583
protected function scanModels()
    {
        $scans = $this->modelScans();

        if (empty($scans)) {
            return;
        }

        $scanner = $this->app->make('annotations.model.scanner');

        $scanner->setClassesToScan($scans);

        file_put_contents(
          $this->finder->getScannedModelsPath(), '<?php '.$scanner->getModelDefinitions()
        );
    }
1104178
private function checkDefinitions(): void {
    // Add many to many stuff if necessary
    foreach($this->unchecked as $def) {
      foreach($def->many_to_many as $relation) {
        //echo "Processing many to many for {$def->name}\n";

        // Set up left keys
        $related = $this->defs[$relation->entity_left];

        if(empty($relation->id_left)) {
          //echo "Setting {$relation->alias_join} id_left to {$related->id->alias}\n";
          $relation->idLeft($related->id->alias);
        }

        if(empty($relation->key_left)) {
          //echo "Setting {$relation->alias_join} key_left to " . keyify($related->name) . "\n";
          $relation->keyLeft(keyify($related->name));
        }
        //

        // Set up right keys
        $related = $this->defs[$relation->entity_right];

        if(empty($relation->id_right)) {
          //echo "Setting {$relation->alias_join} id_right to {$related->id->alias}\n";
          $relation->idRight($related->id->alias);
        }

        if(empty($relation->key_right)) {
          //echo "Setting {$relation->alias_join} key_right to " . keyify($related->name) . "\n";
          $relation->keyRight(keyify($related->name));
        }
        //

        // Left side relations
        $related = $this->defs[$relation->entity_left];

        //echo "Adding {$related->name} hasManyThrough {$relation->alias_join} to {$relation->alias_right}\n";
        $related->hasManyThrough(pluralize($relation->alias_right), $relation->entity_join, $relation->entity_right)
          ->idLocal($relation->id_left)
          ->idForeign($relation->id_right)
          ->keyLocal($relation->key_left)
          ->keyForeign($relation->key_right)
        ;

        if(!array_key_exists($relation->alias_join, $def->has_many)) {
          //echo "Adding {$related->name} hasMany {$def->name}\n";
          $related->hasMany($relation->alias_join, $def->full_name)
            ->localKey  ($relation->id_left)
            ->foreignKey($relation->key_left)
          ;
        }

        if(!array_key_exists($relation->alias_left, $def->belongs_to)) {
          //echo "Adding {$def->name} belongsTo {$related->name}\n";
          $def->belongsTo($relation->alias_left, $related->full_name);
        }
        //

        // Right side relations
        $related = $this->defs[$relation->entity_right];

        //echo "Adding {$related->name} hasManyThrough {$relation->alias_join} to {$relation->alias_left}\n";
        $related->hasManyThrough(pluralize($relation->alias_left), $relation->entity_join, $relation->entity_left)
          ->idLocal($relation->id_right)
          ->idForeign($relation->id_left)
          ->keyLocal($relation->key_right)
          ->keyForeign($relation->key_left)
        ;

        if(!array_key_exists($relation->alias_join, $def->has_many)) {
          //echo "Adding {$related->name} hasMany {$def->name}\n";
          $related->hasMany($relation->alias_join, $def->full_name)
            ->localKey  ($relation->id_right)
            ->foreignKey($relation->key_right)
          ;
        }

        if(!array_key_exists($relation->alias_right, $def->belongs_to)) {
          //echo "Adding {$def->name} belongsTo {$related->name}\n";
          $def->belongsTo($relation->alias_right, $related->full_name);
        }
        //
      }
    }

    // Add has many stuff if necessary
    foreach($this->unchecked as $def) {
      foreach($def->has_many as $relation) {
        //echo "Processing has many for {$def->name}\n";

        $related = $this->defs[$relation->foreign_entity];

        if(empty($relation->local_key)) {
          //echo "Setting {$relation->alias} local_key to {$def->id->alias}\n";
          $relation->localKey($def->id->alias);
        }

        if(empty($relation->foreign_key)) {
          //echo "Setting {$relation->alias} foreign_key to " . keyify($related->name) . "\n";
          $relation->foreignKey(keyify($related->name));
        }
      }
    }

    // Add belongs to stuff if necessary
    foreach($this->unchecked as $def) {
      foreach($def->belongs_to as $relation) {
        //echo "Processing belongs to for {$def->name}\n";

        $related = $this->defs[$relation->foreign_entity];

        if(empty($relation->local_key)) {
          //echo "Setting {$relation->alias} local_key to " . keyify($related->name) . "\n";
          $relation->localKey(keyify($related->name));
        }

        if(empty($relation->foreign_key)) {
          //echo "Setting {$relation->alias} foreign_key to {$def->id->alias}\n";
          $relation->foreignKey($related->id->alias);
        }

        if(!array_key_exists($relation->local_key, $related->required)) {
          //echo "Adding {$def->name} column {$relation->local_key} of type {$related->id->type}\n";
          $def->required($relation->local_key, $related->id->type);
        }
      }
    }

    // We've checked everything in the queue.  Clear it out.
    $this->unchecked = [];
  }
500188
protected function configure(): void
    {
        $this
            ->setName('make:model')
            ->setDescription('Creates a new App model')
            ->addArgument(
                'modelName',
                InputArgument::OPTIONAL,
                'Define the name of the model to create'
            )
            ->addOption(
                'skip-db',
                null,
                InputOption::VALUE_NONE,
                'Skip database table creation'
            )
            ->addOption(
                'skip-seeder',
                null,
                InputOption::VALUE_NONE,
                'Skip seeder creation'
            )
            ->addOption(
                'auto-detect',
                null,
                InputOption::VALUE_NONE,
                'Automatically build models from the database'
            )
            ->addOption(
                'localised',
                null,
                InputOption::VALUE_NONE,
                'Create a localised model (or convert an existing model)'
            );

        if (Components::exists('nails/module-admin')) {
            $this->addOption(
                'admin',
                null,
                InputOption::VALUE_NONE,
                'Create an admin controller'
            );
        }
    }
295644
public function has_table()
    {
        if (null === $this->table) {
            $this->set_error('This model is has no table specified', true);
        } elseif (false === $this->table) {
            return false;
        }
    }
27359
private function validate()
    {
        if ($this->hasValidated) {
            return;
        }

        $this->checkDepth();

        foreach ($this->schema as $rule => $parameter) {
            $this->currentKeyword   = $rule;
            $this->currentParameter = $parameter;
            $this->mergeErrors($this->validateRule($rule, $parameter));
            $this->currentKeyword = $this->currentParameter = null;
        }

        $this->hasValidated = true;
    }