Laravel 10.1: What Controllers Should Return By Default?

preview_player
Показать описание
A small but pretty important change in the minor Laravel 10.1 that had a big community reaction.

- - - - -
Support the channel by checking out my products:

- - - - -
Other places to follow:
Рекомендации по теме
Комментарии
Автор

I think Taylor made the right decision. Let people decide if they want to add return types and what kind. Otherwise you run into the super annoying side effect of having to change the predefined types every time as you mentioned.

flobbos
Автор

I respect you more for they way you handle 'regretful' moments, especially at the end, when you saying you'd work on how to convey your sentiments, that is top-tier man. Bravo!!

brianochieng
Автор

Why not also add a flag to artisan to add the return type? Could have some default ones to cover the commons and also let you specify the complete path to a custom class.

Ajcmaster
Автор

Return the writing style to previous versions is good decision made by the author. It will help a lot for the beginner who still struggle learning Laravel from version 8 or 9. Even, in my opinion, it will help more advance-level of Laravel lovers to not doing extra "work" for their new Laravel project.

TrikNgonlen
Автор

Keep tweeting about this kind of things please! You are doing great job! Laravel is moving to fast, and Taylor has made some "strange" decisions regarding framework.

MarijanKopcic
Автор

To keep on with basic principle of Return type must be there - I think "mixed" is good option. Where community can argue that type "Response" which was originally introduced - can be replaced by View if needed OR using Stubs - the same principle applies to "mixed" return type as well - that if someone wants, they can replace "mixed" with whatever their return type is.

pudlp
Автор

The issue comes down to whether a framework is there to help you develop solutions or to constrain you to a particular view on what is 'good practice'

unarmedwombat
Автор

Once again great job. When I saw the laravel 10 update I was thinking that these return type should not be included, and now thanks to you that they have changed and removed this.♥

mycreativetech
Автор

Honestly, the best option was either Taylor's second PR related to this with the Responsible interface or to do union types. "mixed" was never the right answer since it goes completely against the point of having a return type.

Laravel 10's main hype was embracing return types with the required PHP version being 8.1 or later; and Taylor's final decision took that away from the default stubs for Controllers. Now we pay the price by having to manually re-add the return types to the controller stubs for every project going forward instead of them being there out-of-the-box.

KastsEcho
Автор

The problem is in the view presenter. This layer should always gather a response, and depending on that response display a view, json, xml, etc. This will require a bit of restructuring in Laravel, but will remove this mixed which is useless and shows that there’s a structure problem.

TravisFont
Автор

I think what i would liked to find is a commented section that's provide me a link to explain what can I add to optimize my response as new développer it would help me a lot to understand quickly the benefits and the use of those responses !

angelHighTech
Автор

In my project, I have even 3 types of controller: simple one that returns View, RPC Controller that returns JsonResponse|View, and API. This is tge case when it is better for you to decide what you want to return

cardboarddignity
Автор

I think that this actions of Taylor is not correct cuz he can move return type in controller into the generator command. It can be like this: artisan make:controller WhateverController If you don't pass this param it can generate default type. It will be more correct than remove returning type. It is not a php8 way I think.

ChorumTheDevourer
Автор

Your tweet produced good and healthy friction.

ArjonJasonCastro
Автор

I like to return Renderable in web controllers and I believe the Symfony foundation response in API controllers so I guess I'm more of a fan of interfaces or parent classes I was never a fan of the whole App | Factory | view stuff. I'm not a fan of mixed I guess it does serve the purpose but it's so unspecific that I think no default return type is the better option. I appreciate you using your platform to help influence greatness in the laravel community

TheShadetheory
Автор

Its based on the developers but I think, while generating controller, they can give options like for which tech stack you are generating controller for, for ex. Inertia, Blade, etc and based on that they can add return type in controllers method.

mayanksgajjar
Автор

I think setting it to mixed by default is fine, but it should not stay like this. Say the developer implements the functionality, they should then appropriately change the mixed type to whatever they actually want to return.

Perhaps an IDE should be able to recommend the developer to change the mixed type to the more appropriate one?

ItsDigiUtime
Автор

I think all the opinions are valid for this. Personally I do prefer the return types to be there by default. Yes can be a bit annoying to always have to change them to suit your project. It would be nice if the types would be set based on the project and controller type. For example if the project is initialized with or breeze is installed the controllers are created with sensible default return types like '\Inertia\Response' on the index() method of a resource controller - but we run into again having to change them when required by the project needs - so manually adding them is not a huge hassle

jasonpeters
Автор

Isn't the view() a "response" at some level?

You can use `return response()->view()` i

cloudplayro
Автор

Thank you for being considerdate about your actions, but I'm also happy and grateful you are just you tho. :) Keep up the good work.

Niboros