public function replaceModuleInformation($stub, $modelInformation)
{
// replace table
$stub = str_replace('{{table}}', $modelInformation['table'], $stub);
// replace fillable
$this->fieldsHidden = '';
$this->fieldsFillable = '';
$this->fieldsCast = '';
foreach ($modelInformation['fillable'] as $field) {
// fillable and hidden
if ($field != 'id' && $field != 'created_at' && $field != 'updated_at') {
$this->fieldsFillable .= (strlen($this->fieldsFillable) > 0 ? ', ' : '') . "'{$field}'";
$fieldsFiltered = $this->columns->where('field', $field);
if ($fieldsFiltered) {
// check type
switch (strtolower($fieldsFiltered->first()['type'])) {
case 'timestamp':
$this->fieldsDate .= (strlen($this->fieldsDate) > 0 ? ', ' : '') . "'{$field}'";
break;
case 'datetime':
$this->fieldsDate .= (strlen($this->fieldsDate) > 0 ? ', ' : '') . "'{$field}'";
break;
case 'date':
$this->fieldsDate .= (strlen($this->fieldsDate) > 0 ? ', ' : '') . "'{$field}'";
break;
case 'tinyint(1)':
$this->fieldsCast .= (strlen($this->fieldsCast) > 0 ? ', ' : '') . "'{$field}' => 'boolean'";
break;
}
}
} else {
if ($field != 'id' && $field != 'created_at' && $field != 'updated_at') {
$this->fieldsHidden .= (strlen($this->fieldsHidden) > 0 ? ', ' : '') . "'{$field}'";
}
}
}
// replace in stub
$stub = str_replace('{{fillable}}', $this->fieldsFillable, $stub);
$stub = str_replace('{{hidden}}', $this->fieldsHidden, $stub);
$stub = str_replace('{{casts}}', $this->fieldsCast, $stub);
$stub = str_replace('{{dates}}', $this->fieldsDate, $stub);
$stub = str_replace('{{modelnamespace}}', $this->options['namespace'], $stub);
return $stub;
}