Laravel News Substack

Share this post

Laravel 10 Controller Stub Changes

laravelnews.substack.com

Discover more from Laravel News Substack

Your official news source for the Laravel PHP Framework.
Continue reading
Sign in

Laravel 10 Controller Stub Changes

Laravel removed return types from the controller skeleton.

Laravel News
Feb 22, 2023
Share this post

Laravel 10 Controller Stub Changes

laravelnews.substack.com
Share

One of the new features in Laravel 10 is all the skeletons come with native-type declarations. If you run php artisan make:controller Account --resource then the out output looks like this:

Controller Response return types

The problem occurs because it defaults to a Response return type. So this means returning a view, a string, an array, or literally anything other than a Response to fail.

Thanks for reading Laravel News Substack! Subscribe for free to receive new posts and support my work.

Of course, this is an easy fix and you can just change the method's return type after the stub is generated, but honestly, that doesn't feel very Laravel-like.

One of the nice things about the framework is that it always considers the people new to it and new to PHP in general. This felt backward to that.

There ended up being quite a bit of discussion on a GitHub PR around what should be done here, with suggestions ranging from using mixed to a new interface and everything in between.

At the end of the day, Taylor decided the prudent step forward is removing the Controller stubs' return types. Which, in my opinion, is the right call.

Thanks for reading Laravel News Substack! Subscribe for free to receive new posts and support my work.

Share this post

Laravel 10 Controller Stub Changes

laravelnews.substack.com
Share
Comments
Top
New

No posts

Ready for more?

© 2023 Laravel News
Privacy ∙ Terms ∙ Collection notice
Start WritingGet the app
Substack is the home for great writing