diff --git a/src/Illuminate/Foundation/Console/ModelMakeCommand.php b/src/Illuminate/Foundation/Console/ModelMakeCommand.php index c0116999bdcf..e60a128ebe88 100644 --- a/src/Illuminate/Foundation/Console/ModelMakeCommand.php +++ b/src/Illuminate/Foundation/Console/ModelMakeCommand.php @@ -45,6 +45,7 @@ public function handle() $this->input->setOption('migration', true); $this->input->setOption('controller', true); $this->input->setOption('resource', true); + $this->input->setOption('policy', true); } if ($this->option('factory')) { @@ -58,6 +59,10 @@ public function handle() if ($this->option('controller') || $this->option('resource')) { $this->createController(); } + + if ($this->option('policy')) { + $this->createPolicy(); + } } /** @@ -111,6 +116,21 @@ protected function createController() ]); } + /** + * Create a policy for the model. + * + * @return void + */ + protected function createPolicy() + { + $policy = Str::studly(class_basename($this->argument('name'))); + + $this->call('make:policy', [ + 'name' => "{$policy}Policy", + '--model' => $this->getNameInput(), + ]); + } + /** * Get the stub file for the generator. * @@ -143,9 +163,11 @@ protected function getOptions() ['migration', 'm', InputOption::VALUE_NONE, 'Create a new migration file for the model'], - ['pivot', 'p', InputOption::VALUE_NONE, 'Indicates if the generated model should be a custom intermediate table model'], + ['pivot', null, InputOption::VALUE_NONE, 'Indicates if the generated model should be a custom intermediate table model'], ['resource', 'r', InputOption::VALUE_NONE, 'Indicates if the generated controller should be a resource controller'], + + ['policy', 'p', InputOption::VALUE_NONE, 'Create a new policy for the model'], ]; } }