Skip to content
Merged
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
25 changes: 25 additions & 0 deletions src/Illuminate/Foundation/Console/PolicyMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Illuminate\Foundation\Console;

use Illuminate\Console\GeneratorCommand;
use Illuminate\Contracts\Auth\Access\Authorizable;
use Illuminate\Support\Str;
use Symfony\Component\Console\Input\InputOption;

Expand Down Expand Up @@ -67,6 +68,28 @@ protected function replaceUserNamespace($stub)
);
}

/**
* Get the model for the guard's user provider.
*
* @return string|null
*/
protected function userProviderModel()
{
$config = $this->laravel['config'];

if ($this->option('any-guard')) {
return Authorizable::class;
}

$guard = $this->option('guard')
? $this->option('guard')
: $config->get('auth.defaults.guard');

$provider = $config->get('auth.guards.'.$guard.'.provider');

return $config->get("auth.providers.{$provider}.model");
}

/**
* Replace the model for the given stub.
*
Expand Down Expand Up @@ -160,6 +183,8 @@ protected function getOptions()
{
return [
['model', 'm', InputOption::VALUE_OPTIONAL, 'The model that the policy applies to'],
['guard', 'g', InputOption::VALUE_OPTIONAL, 'The guard that the policy relies on'],
['any-guard', null, InputOption::VALUE_NONE, 'Allow use with any authorizable model (overrides --guard)'],
];
}
}