-
Notifications
You must be signed in to change notification settings - Fork 11k
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
Artisan command make:policy generates invalid policy code with a non-default user provider configuration #40345
Comments
Just tested it with a new Laravel Project:
Output:
|
@hmennen90 check the generated policy code. |
The Target Models are in use Statements using App\Models Namespace in both cases: -m and --model If no Model is specified, there is a blank Policy created
|
hmm i try it on php 8.0 - i'm currently on 8.1.1 |
Results on PHP8.0 and PHP7.4 are same as at PHP8.1.1 Maybe anyone else can reproduce your issue? |
@slavicd command back ;-) Can now confirm your issue also on PHP 8.1.1 - had the config cached... Did you mean the following Output?
|
You're changing the guard to one that doesn't have a model. Then it's normal that you'll get an error. A policy always requires a model. |
@driesvints the command is generating invalid code. The problem is that I am not getting an error. The fact that I have a custom user provider is not documented anywhere as related to this, and even if it were, spitting out an error or warning or an explanatory message all seem more appropriate than generating a half-stub that is really hard to decode. |
@slavicd ah I see what you mean. What would need to happen here is that the |
Precisely. I'll try to write a PR now. |
#40348) * Fixes issue #40345 * Addresses coding style complaint. * Update PolicyMakeCommand.php * Update PolicyMakeCommand.php * use default user model Co-authored-by: Taylor Otwell <[email protected]>
Description:
php artisan make:policy
will produce invalid output, similar to what's been reported here, here and here (missing user class) if a non-defaultauth.providers.users
configuration is in place.Steps To Reproduce:
composer create-project laravel/laravel
php artisan make:policy CommentPolicy --model=Comment
Note the generated code in Policies: it is missing the User class and is invalid.
I realized this happens when the provider configuration is missing the
model
key, which was my case too (except I had a custom driver, and I never needed themodel
key).Expected behaviour
The
make:policy
command throws an error if it needs explicit user class configuration or otherwise inserts a default user class.The text was updated successfully, but these errors were encountered: