Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.8] added policy option in model make command #28393

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/Illuminate/Foundation/Console/ModelMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand All @@ -58,6 +59,10 @@ public function handle()
if ($this->option('controller') || $this->option('resource')) {
$this->createController();
}

if ($this->option('policy')) {
$this->createPolicy();
}
}

/**
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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'],
];
}
}