Skip to content

Commit

Permalink
[9.x] Make:model --morph flag to generate MorphPivot model (#41011)
Browse files Browse the repository at this point in the history
* add stub

* update model command to handle morph pivot

* formatting

* add files

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
michael-rubel and taylorotwell authored Feb 14, 2022
1 parent 7966b9b commit d3ee810
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/Illuminate/Foundation/Console/ModelMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,15 @@ protected function createPolicy()
*/
protected function getStub()
{
return $this->option('pivot')
? $this->resolveStubPath('/stubs/model.pivot.stub')
: $this->resolveStubPath('/stubs/model.stub');
if ($this->option('pivot')) {
return $this->resolveStubPath('/stubs/model.pivot.stub');
}

if ($this->option('morph-pivot')) {
return $this->resolveStubPath('/stubs/model.morph-pivot.stub');
}

return $this->resolveStubPath('/stubs/model.stub');
}

/**
Expand Down Expand Up @@ -213,6 +219,7 @@ protected function getOptions()
['factory', 'f', InputOption::VALUE_NONE, 'Create a new factory for the model'],
['force', null, InputOption::VALUE_NONE, 'Create the class even if the model already exists'],
['migration', 'm', InputOption::VALUE_NONE, 'Create a new migration file for the model'],
['morph-pivot', null, InputOption::VALUE_NONE, 'Indicates if the generated model should be a custom polymorphic intermediate table model'],
['policy', null, InputOption::VALUE_NONE, 'Create a new policy for the model'],
['seed', 's', InputOption::VALUE_NONE, 'Create a new seeder for the model'],
['pivot', 'p', InputOption::VALUE_NONE, 'Indicates if the generated model should be a custom intermediate table model'],
Expand Down
10 changes: 10 additions & 0 deletions src/Illuminate/Foundation/Console/stubs/model.morph-pivot.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace {{ namespace }};

use Illuminate\Database\Eloquent\Relations\MorphPivot;

class {{ class }} extends MorphPivot
{
//
}

0 comments on commit d3ee810

Please sign in to comment.