Skip to content
This repository has been archived by the owner on Apr 10, 2020. It is now read-only.

Commit

Permalink
Closes #19
Browse files Browse the repository at this point in the history
  • Loading branch information
rossity committed Oct 29, 2018
1 parent 0efd75c commit e54bb02
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/Console/GenerateModelCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,22 @@ protected function createModel()
],
$this->getStub('relation')
);
$modelTemplate = str_replace(['{{relation}}'], [$relationTemplate], $modelTemplate);
$modelTemplate = str_replace(
[
'{{relation}}',
'{{guardedAttributes}}'
],
[
$relationTemplate,
", '" . snake_case($related['name']) . "_id'"
],
$modelTemplate
);

$modelTemplate = $this->removeTag($modelTemplate, 'belongsTo');
} else {
$modelTemplate = $this->removeBlock($modelTemplate, 'belongsTo');
$modelTemplate = $this->removeBlock($modelTemplate, 'guardedAttributes');
}

$modelTemplate = $this->logActivity ? $this->removeTag($modelTemplate, 'logsActivity') : $this->removeBlock($modelTemplate, 'logsActivity');
Expand Down
2 changes: 1 addition & 1 deletion stubs/model.stub
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class {{modelName}} extends Model{{hasMedia}} implements HasMedia{{/hasMedia}}

protected static $logAttributes = ['*'];
protected static $logOnlyDirty = true;{{/logsActivity}}
protected $guarded = [];
protected $guarded = ['id'{{guardedAttributes}}];

{{belongsTo}}{{relation}}{{/belongsTo}}
}

0 comments on commit e54bb02

Please sign in to comment.