|
3 | 3 | namespace Illuminate\Foundation\Console; |
4 | 4 |
|
5 | 5 | use Illuminate\Console\GeneratorCommand; |
| 6 | +use Illuminate\Contracts\Auth\Access\Authorizable; |
6 | 7 | use Illuminate\Support\Str; |
7 | 8 | use Symfony\Component\Console\Input\InputOption; |
8 | 9 |
|
@@ -67,6 +68,28 @@ protected function replaceUserNamespace($stub) |
67 | 68 | ); |
68 | 69 | } |
69 | 70 |
|
| 71 | + /** |
| 72 | + * Get the model for the guard's user provider. |
| 73 | + * |
| 74 | + * @return string|null |
| 75 | + */ |
| 76 | + protected function userProviderModel() |
| 77 | + { |
| 78 | + $config = $this->laravel['config']; |
| 79 | + |
| 80 | + if ($this->option('any-guard')) { |
| 81 | + return Authorizable::class; |
| 82 | + } |
| 83 | + |
| 84 | + $guard = $this->option('guard') |
| 85 | + ? $this->option('guard') |
| 86 | + : $config->get('auth.defaults.guard'); |
| 87 | + |
| 88 | + $provider = $config->get('auth.guards.'.$guard.'.provider'); |
| 89 | + |
| 90 | + return $config->get("auth.providers.{$provider}.model"); |
| 91 | + } |
| 92 | + |
70 | 93 | /** |
71 | 94 | * Replace the model for the given stub. |
72 | 95 | * |
@@ -160,6 +183,8 @@ protected function getOptions() |
160 | 183 | { |
161 | 184 | return [ |
162 | 185 | ['model', 'm', InputOption::VALUE_OPTIONAL, 'The model that the policy applies to'], |
| 186 | + ['guard', 'g', InputOption::VALUE_OPTIONAL, 'The guard that the policy relies on'], |
| 187 | + ['any-guard', null, InputOption::VALUE_NONE, 'Allow use with any authorizable model (overrides --guard)'], |
163 | 188 | ]; |
164 | 189 | } |
165 | 190 | } |
0 commit comments