Align return type of controller methods #40891
Unanswered
olivernybroe
asked this question in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Laravel recently aligned the return types of builders, so they all implement the same interface, making type hinting really easy and straightforward, plus it helps the IDE and phpstan quite a lot. #37956
This issue here is about also aligning the return types of controller method data. Normally people use
response
giving you aIlluminate\Http\Response
instanceredirect
giving you a\Illuminate\Http\RedirectResponse
instanceview
giving you a\Illuminate\Contracts\View\View
instanceresponse#json
giving you a\Illuminate\Http\JsonResponse
instanceresponse#stream
giving you a\Symfony\Component\HttpFoundation\StreamedResponse
instanceresponse#download
giving you a\Symfony\Component\HttpFoundation\BinaryFileResponse
instanceThere are probably more which I missed.
What I am suggesting here is aligning them all to implement the same interface, like it was done with the builder.
By having a unified interface I wouldn't have to change the return type because I changed it to a redirect instead of a json response.
A possibility could be to use the currently existing
Renderable
interface, but might be some problems with that which I haven't thought of.Beta Was this translation helpful? Give feedback.
All reactions