-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[8.x] New flag --requests -R to make:controller and make:model Commands #39120
Conversation
For me the "make everything" method is I am not suggesting to remove anything, but that proxying the new flags from |
Thanks @tontonsb
I thought about it, but to me, it feels like opening a deeper "rabbit hole / inception". So now sure how elegant it would be Opinions? |
I think @tontonsb has a pretty good point but I also do not have a good solution for the shortcut... only thing I can think of is |
Maybe PS: If we introduced uppercase letters, |
I think @caugner's suggestion of capital R is not bad. |
@caugner great suggestion about |
Just to add two more ideas:
|
That might be a bit out of scope on this PR 😅 |
@caugner I agree with @taylorotwell - I guess I will create a full wizard with bells and whistles in the future :) |
It's not an "if". We already have However, |
@PovilasKorop I personally only think you should include the |
|
||
$namespacedRequests = $namespace.'\\'.$storeRequestClass.';'; | ||
if ($storeRequestClass != $updateRequestClass) { | ||
$namespacedRequests .= "\r\nuse ".$namespace.'\\'.$updateRequestClass.';'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use of \r here is not a UNIX standard linebreak.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TomHAnderson good notice, fixed in these:
I think this PR should include a reference to a complimentary PR in the docs. |
Yup, agreed, me too. Removed the singular Also, pushed the changes for @TomHAnderson will submit a PR to the docs then this PR is fully merged, then I will know which flag to put where in the docs. |
Slightly related, I tweeted about a proof of concept for gif.mp4I think a similar interactive mode for |
@taylorotwell sorry for pushing but is there any reason why this PR wasn't merged/released in 20 days? Anything I still need to improve here? |
I have mainly been hesitating because this is somewhat related to and close to functionality I was considering building in a So, I've been debating if I want to pursue that package or not so that has caused the hesitation here. |
@taylorotwell ok feel free to take over, this would be similar to "full wizard with bells and whistles in the future" I was referring to, earlier. To be honest, there are a lot of CRUD generator packages/services on the market already, so that functionality is largely covered by those packages. But I think the community would appreciate something like that inside the framework itself. Just keep in mind the potential overhead of all the potential combinations of those files that may have their content depending on each other, at least in my experience the scope can grow quite quickly. But if you're up for the challenge, go for it, and let me know if I can contribute. |
I vote for this solution so I can stop maintaining Larawiz. |
@PovilasKorop Thanks for this PR! Would you consider a follow-up release to create the Request files in the correct subfolder? Saves time to move 2 files and edit 3 of them. Or is that blocked by default Laravel behaviour? Simple example
This will create a new model under App\Models\Accounting |
@dragonfly4 I thought about it but had a doubt if everyone would want to create subfolders for the requests exactly as for models. Also, it would require quite a lot of work to make it properly, for now I moved on to other work and don't have that much time, sorry |
This PR adds a new flag to
php artisan make:controller
command, which creates FormRequest class and uses it immediately in the generated controller.Problem
How I personally use Resourceful Controllers with Form Requests:
php artisan make:controller UserController --resource
php artisan make:request StoreUserRequest
php artisan make:request UpdateUserRequest
UserController
and manually replaceIlluminate\Http\Request
with those new FormRequest classesWhy couldn't we generate it all at once?
This problem resonated with my Twitter audience, with 180+ likes on this Tweet.
My Proposed Solution (updated October 7)
Now, when you run
php artisan make:controller UserController --resource --model=User --requests
, it will generate two FormRequest classes:StoreUserRequest
andUpdateUserRequest
, and will replace them in the Controller.A short version of
--requests
flag is-R
, not to mix with-r
for resources.It is done by reusing the
make:request
command and calling it with appropriate class name.This functionality works only together with
--model
flag, otherwise it would be impossible/hard to guess the name for the FormRequest classes.Also, it works one "layer" above in the Model:
php artisan make:model Project -mcrR
would generateStoreProjectRequest
andUpdateProjectRequest
Breaking changes
It shouldn't break any existing functionality, it's just a new flag. If that flag isn't used, it all falls back to the old default values.
Any other suggestions for improvement are welcome.