Builds the model class with the given name.

@return string
764158
public function handle()
    {
        $input = $this->getCommandInput();

        $resource = Resource::fromFile($input->resourceFile, $input->languageFileName);

        $destenationFile = $this->getDestenationFile($input->modelName, $input->modelDirectory);

        if ($this->hasErrors($resource, $destenationFile)) {
            return false;
        }

        $fields = $resource->fields;
        if ($input->useSoftDelete) {
            $fields = $this->upsertDeletedAt($fields);
        }

        $stub = $this->getStubContent('model');
        $primaryField = $this->getPrimaryField($fields);
        $relations = $this->getRelationMethods($resource->relations, $fields);

        return $this->replaceTable($stub, $resource->getTableName($input->table))
            ->replaceModelName($stub, $input->modelName)
            ->replaceNamespace($stub, $this->getNamespace($input->modelName, $input->modelDirectory))
            ->replaceSoftDelete($stub, $input->useSoftDelete)
            ->replaceTimestamps($stub, $this->getTimeStampsStub($input->useTimeStamps, $resource->isCreateAndUpdateAtManaged()))
            ->replaceFillable($stub, $this->getFillables($stub, $fields))
            ->replaceDateFields($stub, $this->getDateFields($stub, $fields))
            ->replaceCasts($stub, $this->getCasts($stub, $fields))
            ->replacePrimaryKey($stub, $this->getNewPrimaryKey($primaryField, $input->primaryKey))
            ->replaceRelationshipPlaceholder($stub, $relations)
            ->replaceAccessors($stub, $this->getAccessors($fields))
            ->replaceMutators($stub, $this->getMutators($fields))
            ->createFile($destenationFile, $stub)
            ->info('A model was crafted successfully.');
    }
1092465
protected function buildClass($name){
        $controllerNamespace = $this->getNamespace($name);
        $replace = [
            'DummyContract' => $this->getNameInput(),
        ];
        //dd($replace);
        return str_replace(
            array_keys($replace), array_values($replace), parent::buildClass($name)
        );
    }
60875
protected function buildClass($name)
    {
        $stub = parent::buildClass($name);

        if ($model = $this->argument('model')) {
            if (!starts_with($model, $namespace = $this->laravel->getNamespace())) {
                $model = "{$namespace}\\{$model}";
            }
        }

        return $this->replaceModel($stub, $model);
    }
888676
protected function buildClass($name)
    {
        $model = $this->parseModel($this->option('model'));

        if (empty(trim($model, $this->laravel->getNamespace().'Models'))) {
            $model = $this->parseModel($this->ask('witch model do you want to injected to the repository?'));
        }

        if (! class_exists($model)) {
            if ($this->confirm("A {$model} model does not exist. Do you want to generate it?", true)) {
                $this->call('make:model', ['name' => $model]);
            }
        }

        $stub = $this->files->get($this->getStub());

        return $this->replaceNamespace($stub, $name)
            ->replaceModelClass($stub, $model)
            ->replaceClass($stub, $name);
    }
675689
private function buildChild() {
        $class = new Object\Index($this->getConfiguration());
        $class->setName(ucfirst($this->getTableName()));
        $class->setAbstract(false);
        $class->setExtends('GeneratedParent');

        $class->setNamespace(
            $this->getConfiguration()->getRootNamespace()
            . '\Models\\' . $this->getConfiguration()->getModelSubNamespace()
        );
        $class->addUse(
            $this->getConfiguration()->getRootNamespace()
            . '\Models\\' . $this->getConfiguration()->getModelSubNamespace()
            . '\Generated\\' . ucfirst($this->getTableName()) . ' as GeneratedParent'
        );
        $method = new Object\Method();
        $method->setDescription('This should set any defaults to the current object');
        $method->setName('loadDefaults');
        $method->setContent('//TODO');
        $method->setAccess('public');
        $method->setReturnType('void');
        $class->addMethod($method);

        return $class;
    }
260251
protected function buildClass($name)
    {
        if ($name == $this->qualifyClass('ModelPolicy')) {
            $stub = $this->files->get($this->getStub($name));

            $parent = $this->replaceNamespace($stub, $name)->replaceClass($stub, $name);

            $stub = $this->replaceUserNamespace($parent);

            $model = $this->option('model');

            return $model ? $this->replaceModel($stub, $model) : $stub;
        }

        return parent::buildClass($name);
    }
979444
protected function createModel()
	{
		$name = str_singular( $this->name );
		$tmpl = file_get_contents( __DIR__ . "/Model.tmpl" );
		$tmpl = str_replace( [ '{{NAME}}', '{{NAMESPACE}}' ], [ $name, $this->namespace ], $tmpl );
		$path = app_path( "Models/{$name}.php" );
		if( ! file_exists( $path ) ) {
			file_put_contents( $path, $tmpl );
		}
	}
682978
protected function buildClass($name)
    {
        $controllerNamespace = $this->getNamespace($name);

        $replace = [];

        if ($this->option('parent')) {
            $replace['DummyFullParentClass'] = $controllerNamespace.'Controller';
            $replace['DummyParentClass'] = class_basename($controllerNamespace.'Controller');
            $replace['parent_dummy_view'] = $this->getParentViewName($name);
            $replace['parent_dummy_route'] = $this->getParentRouteName($name);
        }
        $replace['dummy_view'] = $this->getViewName($name);
        $replace['dummy_route'] = $this->getRouteName($name);

        return str_replace(array_keys($replace), array_values($replace), parent::buildClass($name));
    }
1188234
protected function buildClass($name)
    {
        $replace = [];

        $replace['dummy_route'] = $this->getRouteName($name);

        return str_replace(array_keys($replace), array_values($replace), parent::buildClass($name));
    }
242406
protected function buildClass($name)
    {
        $stub = $this->files->get($this->getStub());

        $table = $this->option('table') ?: $this->argument('name');
        $fillable = $this->option('fillable');

        return $this->replaceNamespace($stub, $name)
            ->replaceTable($stub, $table)
            ->replaceFillable($stub, $fillable)
            ->replaceClass($stub, $name);
    }
570173
protected function buildClass($name)
	{
		$stub = parent::buildClass($name);

		$event = $this->option('event');

		if ( ! starts_with($event, $this->getAppNamespace()))
		{
			$event = $this->getAppNamespace().'Events\\'.$event;
		}

		$stub = str_replace(
			'{{event}}', class_basename($event), $stub
		);

		$stub = str_replace(
			'{{fullEvent}}', $event, $stub
		);

		return $stub;
	}
452722
protected function buildClass($name)
    {
        $stub = $this->files->get($this->getStub());

        $viewPath = $this->option('view-path') ? $this->option('view-path') . '.' : '';
        $crudName = strtolower($this->option('crud-name'));
        $crudNameSingular = str_singular($crudName);
        $modelName = $this->option('model-name');
        $modelNamespace = $this->option('model-namespace');
        $routeGroup = ($this->option('route-group')) ? $this->option('route-group') . '/' : '';
        $routePrefix = ($this->option('route-group')) ? $this->option('route-group') : '';
        $routePrefixCap = ucfirst($routePrefix);
        $perPage = intval($this->option('pagination'));
        $viewName = snake_case($this->option('crud-name'), '-');
        $fields = $this->option('fields');
        $validations = rtrim($this->option('validations'), ';');

        $validationRules = '';
        if (trim($validations) != '') {
            $validationRules = "\$this->validate(\$request, [";

            $rules = explode(';', $validations);
            foreach ($rules as $v) {
                if (trim($v) == '') {
                    continue;
                }

                // extract field name and args
                $parts = explode('#', $v);
                $fieldName = trim($parts[0]);
                $rules = trim($parts[1]);
                $validationRules .= "\n\t\t\t'$fieldName' => '$rules',";
            }

            $validationRules = substr($validationRules, 0, -1); // lose the last comma
            $validationRules .= "\n\t\t]);";
        }

        if (\App::VERSION() < '5.3') {
            $snippetUp = <<<EOD
        if (\$request->hasFile('{{fieldName}}')) {
            \$file = \$request->file('{{fieldName}}');
            \$fileName = str_random(40) . '.' . \$file->getClientOriginalExtension();
            \$destinationPath = storage_path('/app/public/uploads');
            \$file->move(\$destinationPath, \$fileName);
            \$requestData['{{fieldName}}'] = 'uploads/' . \$fileName;
        }
EOD;
        } else {
            $snippetCreateOne = <<<EOD
        if (\$request->has('{{fieldName}}')) {
            \${{fieldName}}Name = str_random(40) . '.' . \$request->{{fieldName}}->extension();
            \$requestData['{{fieldName}}'] = \${{fieldName}}Name;
        }
EOD;
            $snippetCreateTwo = <<<EOD
        if (\$request->has('{{fieldName}}')) {
            \$path = '/uploads/{{crudName}}/' . \$store->id . '/';
            Storage::makeDirectory(\$path );
            Image::make(\$request->{{fieldName}})->resize(120, 120, function (\$constraint) {
                \$constraint->aspectRatio();
            })->save(public_path(\$path . \${{fieldName}}Name));
            Image::make(\$request->{{fieldName}})->resize(300, 300, function (\$constraint) {
                \$constraint->aspectRatio();
            })->save(public_path(\$path . 'big' . \${{fieldName}}Name));
        }
EOD;
            $snippetUp = <<<EOD
        if (\$request->has('{{fieldName}}')) {
            \${{fieldName}}Name = str_random(40) . '.' . \$request->{{fieldName}}->extension();
            \$requestData['{{fieldName}}'] = \${{fieldName}}Name;
            \$path = '/uploads/{{crudName}}/' . \$up->id . '/';
            if (!empty(\$up->{{fieldName}})) {
                Storage::delete(\$path . \$up->{{fieldName}});
                Storage::delete(\$path . 'big' . \$up->{{fieldName}});
            }
            Storage::makeDirectory(\$path );
            Image::make(\$request->{{fieldName}})->resize(120, 120, function (\$constraint) {
                \$constraint->aspectRatio();
            })->save(public_path(\$path . \${{fieldName}}Name));
            Image::make(\$request->{{fieldName}})->resize(300, 300, function (\$constraint) {
                \$constraint->aspectRatio();
            })->save(public_path(\$path . 'big' . \${{fieldName}}Name));
        }
EOD;
            $snippetDelPicture = <<<EOD
        if (!empty(\$del->{{fieldName}})) {
            \$path = '/uploads/{{crudName}}/' . \$del->id . '/';
                Storage::deleteDirectory(\$path);
        }
EOD;
        }


        $fieldsArray = explode(';', $fields);
        $fileSnippetCreateOne = '';
        $fileSnippetCreateTwo = '';
        $fileSnippetUp = '';
        $fileSnippetDelPicture = '';
        $whereSnippet = '';

        if ($fields) {
            $x = 0;
            foreach ($fieldsArray as $index => $item) {
                $itemArray = explode('#', $item);

                if (trim($itemArray[1]) == 'file') {
                    $fileSnippetCreateOne .= str_replace(['{{fieldName}}', '{{crudName}}', '{{modelName}}'], [trim($itemArray[0]), $crudName, $modelName], $snippetCreateOne) . "\n";
                    $fileSnippetCreateTwo .= str_replace(['{{fieldName}}', '{{crudName}}', '{{modelName}}'], [trim($itemArray[0]), $crudName, $modelName], $snippetCreateTwo) . "\n";
                    $fileSnippetUp .= str_replace(['{{fieldName}}', '{{crudName}}', '{{modelName}}'], [trim($itemArray[0]), $crudName, $modelName], $snippetUp) . "\n";
                    $fileSnippetDelPicture .= str_replace(['{{fieldName}}', '{{crudName}}', '{{modelName}}'], [trim($itemArray[0]), $crudName, $modelName], $snippetDelPicture) . "\n";
                }

                $fieldName = trim($itemArray[0]);

                $whereSnippet .= ($index == 0) ? "where('$fieldName', 'LIKE', \"%\$keyword%\")" . "\n                " : "->orWhere('$fieldName', 'LIKE', \"%\$keyword%\")" . "\n                ";
            }

            $whereSnippet .= "->";
        }

        return $this->replaceNamespace($stub, $name)
            ->replaceViewPath($stub, $viewPath)
            ->replaceViewName($stub, $viewName)
            ->replaceCrudName($stub, $crudName)
            ->replaceCrudNameSingular($stub, $crudNameSingular)
            ->replaceModelName($stub, $modelName)
            ->replaceModelNamespace($stub, $modelNamespace)
            ->replaceModelNamespaceSegments($stub, $modelNamespace)
            ->replaceRouteGroup($stub, $routeGroup)
            ->replaceRoutePrefix($stub, $routePrefix)
            ->replaceRoutePrefixCap($stub, $routePrefixCap)
            ->replaceValidationRules($stub, $validationRules)
            ->replacePaginationNumber($stub, $perPage)
            ->replaceFileSnippetCreateOne($stub, $fileSnippetCreateOne)
            ->replaceFileSnippetCreateTwo($stub, $fileSnippetCreateTwo)
            ->replaceFileSnippetUp($stub, $fileSnippetUp)
            ->replaceFileSnippetDelPicture($stub, $fileSnippetDelPicture)
            ->replaceWhereSnippet($stub, $whereSnippet)
            ->replaceClass($stub, $name);
    }
1366737
public function getModelClass()
    {
        $map = config('db-exporter.model.map');

        $namespace = config('db-exporter.model.namespace');
        $class     = snake_case($this->getTable()->getTableName());

        foreach ($map as $item) {
            // Find matching table name
            $tablePattern = '/' . str_replace('/', '\/', $item['tablePattern']) . '/';
            if (preg_match($tablePattern, $this->table->getTableName()) === 1) {

                $namespace = $item['namespace'];

                if ($item['className'] !== null) {
                    $pattern     = '/' . str_replace('/', '\/', $item['className']['pattern']) . '/';
                    $replacement = $item['className']['replacement'];
                    echo $replacement;
                    $class = preg_replace($pattern, $replacement, $class);
                }
                break;
            }
        }

        return $namespace . '\\' . studly_case(str_singular($class));
    }
136245
protected function getModel()
    {
        if (! $this->model) {
            $this->model = $this->createModel();

            $this->prepareModel($this->model);
        }

        return $this->model;
    }
237126
public function getModel()
    {

        if ($this->modelClass == null) {
            (new LogMessage())->writeError('No modelClass defined');
            return;
        }


        $model = (new ModelFactory())->getModelByClassName($this->modelClass);
        return $model;

    }
822780
public function getModelBaseClass()
    {
        // Use the non-plural version of the controller name if no model
        // is already specified.
        if (empty($this->modelBaseClass)) {
            $this->modelBaseClass = Str::singular(str_replace('Controller', '', class_basename($this)));
        }

        return $this->modelBaseClass;
    }
285831
public function getModelInstance()
    {
        if ($this->instance !== null) {
            return $this->instance;
        }
        $model = $this->getModel();
        if ($model === false) {
            return false;
        }
        $instance = new $model();

        return $instance;
    }