Replace the model for the given stub.

@param string $stub
@param string $model

@return string
491207
protected function replaceModel($stub, $model): string
    {
        $model = str_replace('/', '\\', $model);

        $namespaceModel = $this->rootNamespace().'\Models\\'.$model;

        if (starts_with($model, '\\')) {
            $stub = str_replace('NamespacedDummyModel', trim($model, '\\'), $stub);
        } else {
            $stub = str_replace('NamespacedDummyModel', $namespaceModel, $stub);
        }

        $stub = str_replace(
            "use {$namespaceModel};\nuse {$namespaceModel};", "use {$namespaceModel};", $stub
        );

        $model = class_basename(trim($model, '\\'));

        $stub = str_replace('DummyModel', $model, $stub);

        return str_replace('dummyModel', camel_case($model), $stub);
    }
106116
protected function replaceNamespace(array $segments, $stub)
	{
		if (count($segments) > 1)
		{
			$namespace = implode('\\', array_slice($segments, 0, -1));

			return str_replace('{{namespace}}', ' namespace '.$namespace.';', $stub);
		}
		else
		{
			return str_replace('{{namespace}}', '', $stub);
		}
	}
675327
protected function replaceClass($stub, $name)
    {
        $formGenerator = $this->formGenerator;

        $stub = str_replace(
            '{{class}}',
            $formGenerator->getClassInfo($name)->className,
            $stub
        );

        $stub = str_replace(
            '{{model}}',
            $formGenerator->getClassModel($this->model),
            $stub
        );

        $stub = str_replace(
            '{{datatable}}',
            $this->datatable,
            $stub
        );


        $stub = str_replace(
            '{{trait}}',
            $formGenerator->getTrait($this->states),
            $stub
        );


        $stub = str_replace(
            '{{app}}',
            $this->getAppNamespace(),
            $stub
        );

        $stub = str_replace(
            '{{implement}}',
            $formGenerator->getImplementation($this->states),
            $stub
        );

        $stub = str_replace(
            '{{form}}',
            $this->form,
            $stub
        );

        return $stub;
    }
781631
protected function replaceClass($stub, $name)
    {
        $stub = str_replace('{{class}}',$this->parseName($name), $stub);
        return $stub;
    }
667350
protected function replaceFillable(&$stub, $fields){

        $fillable = [];
        foreach ($fields as $f){
            if($f['add_to']=='fillable') $fillable[] = "\"{$f['name']}\"";
        }
        if(count($fillable)) $fillable = "protected \$fillable = [".implode(',',$fillable)."];";
        else $fillable = "";

        $stub = str_replace('DummyFillable', $fillable, $stub);

        return $this;
    }
1374129
protected function replaceVersioned($versionTable, &$stub)
    {
        if (! $versionTable) {
            $stub = str_replace('{{versioned}}', $this->getArrayAsText([]), $stub);
            return;
        }

        $versioned = [];
        foreach ($versionTable['columns'] as $column) {
            if (! $column['primary'] || $column['name'] == 'version') {
                $versioned[] = $column['name'];
            }
        }
        $stub = str_replace('{{versioned}}', $this->getArrayAsText($versioned), $stub);
    }
993299
private function replaceModelPath(&$stub)
    {

        $model_name = $this->getAppNamespace() . $this->scaffoldCommandObj->getObjName('Name');
        $stub = str_replace('{{model_path}}', $model_name, $stub);

        return $this;

    }
1107350
protected function formatStub($stub)
	{
		$stub = str_replace('{{class}}', $this->input->getArgument('name'), $stub);

		if ( ! is_null($this->option('command')))
		{
			$stub = str_replace('command:name', $this->option('command'), $stub);
		}

		return $this->addNamespace($stub);
	}
1353332
protected function replaceFieldName(&$stub, $name)
    {
        $stub = $this->strReplace('field_name', $name, $stub);
        $stub = $this->strReplace('field_name_cap', ucwords(camel_case($name)), $stub);

        return $this;
    }
1291209
protected function replaceClassName(&$stub)
    {

        $className = $this->scaffoldCommandObj->getObjName('Name') . 'Controller';
        $stub = str_replace('{{class}}', $className, $stub);

        return $this;
    }
1111537
protected function replaceClass($stub, $name)
    {
        $stub = parent::replaceClass($stub, $name . 'Transformer');
        $stub = str_replace('Dummy', ucfirst($this->argument('name')), $stub);
        $stub = str_replace('dummy', lcfirst($this->argument('name')), $stub);

        if ($this->argument('include')) {
            $stub = str_replace('Item', ucfirst($this->argument('include')), $stub);
            $stub = str_replace('item', lcfirst($this->argument('include')), $stub);
        }

        return $stub;
    }
980438
protected function replaceTable(&$stub, $name)
    {
        $class = str_replace($this->getNamespace($name).'\\', '', $name);

        $table = Str::plural(strtolower($class)) !== $this->tableName ? "protected \$table = '$this->tableName';\n" : '';

        $stub = str_replace('DummyModelTable', $table, $stub);

        return $this;
    }
313334
protected function replaceNamespace(string $stub):string
    {
        if (method_exists($this->laravel, 'getNameSpace')) {
            $namespace = $this->laravel->getNamespace() . 'Transformers';
        } else {
            $namespace = 'App\Transformers';
        }

        $stub = str_replace('DummyNamespace', $namespace, $stub);

        return $stub;
    }
1254399
protected function replaceSchemaIndex(&$stub)
    {

        if ($schema = $this->scaffoldCommandObj->option('schema')) {
            $schemaArray = (new SchemaParser)->parse($schema);
        }


        // Create view index header fields
        $schema = (new SyntaxBuilder)->create($schemaArray, $this->scaffoldCommandObj->getMeta(), 'view-index-header');
        $stub = str_replace('{{header_fields}}', $schema, $stub);


        // Create view index content fields
        $schema = (new SyntaxBuilder)->create($schemaArray, $this->scaffoldCommandObj->getMeta(), 'view-index-content');
        $stub = str_replace('{{content_fields}}', $schema, $stub);


        return $this;
    }
1353976
protected function replaceUserNamespace($stub)
    {
        $model = $this->userProviderModel();

        if (! $model) {
            return $stub;
        }

        return str_replace(
            $this->rootNamespace().'User',
            $model,
            $stub
        );
    }
1039781
protected function replaceMapping($entityMetadata, &$stub)
    {
        $attributes = [];
        foreach ($entityMetadata['attributes'] as $attributeMetadata) {
            $attributes[$attributeMetadata['name']] = $attributeMetadata['columnName'];
        }

        $embeddeds = [];
        foreach ($entityMetadata['embeddeds'] as $embeddedMetadata) {
            $embedded = [];
            $embedded['class'] = $embeddedMetadata['class'];
            $embedded['columnPrefix'] = $embeddedMetadata['columnPrefix'];
            $embeddedAttributes = [];
            foreach ($embeddedMetadata['attributes'] as $attributeMetadata) {
                $embeddedAttributes[$attributeMetadata['name']] = $attributeMetadata['columnName'];
            }
            $embedded['attributes'] = $embeddedAttributes;
            $embeddeds[$embeddedMetadata['name']] = $embedded;
        }

        $relations = [];
        foreach ($entityMetadata['relations'] as $relationMetadata) {
            $relation = [];
            
            $relation['type'] = $relationMetadata['type'];
            if ($relation['type'] == 'belongsToMany' || $relation['type'] == 'morphToMany') {
                $relation['inverse'] = (! empty($relationMetadata['options']['inverse']));
            }

            $relations[$relationMetadata['name']] = $relation;
        }

        $mapping = [
            'attributes' => $attributes,
            'embeddeds' => $embeddeds,
            'relations' => $relations,
        ];

        $stub = str_replace('{{mapping}}', $this->getArrayAsText($mapping), $stub);
    }
201467
protected function replaceSchema(&$stub)
    {
        $schema = '';
        if (!$this->optionPlain()) {
            if ($schema = $this->optionSchema()) {
                $schema = (new SchemaParser)->parse($schema);
            }

            $schema = (new SyntaxBuilder)->create($schema, $this->meta);
        }

        $stub = str_replace(['{{schema_up}}', '{{schema_down}}'], $schema, $stub);

        return $this;
    }