Skip to content

Commit

Permalink
Add option to specify a custom guard for the policy
Browse files Browse the repository at this point in the history
  • Loading branch information
ghostal committed Jun 14, 2020
1 parent 0280ddc commit 0ee21ed
Showing 1 changed file with 25 additions and 0 deletions.
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)'],
];
}
}

0 comments on commit 0ee21ed

Please sign in to comment.