Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
[6.x] Allow response to return first view #30651
There are currently a couple ways to return a view. The simple standard way is:
return view('my/view', ['data']);
If you need to customize the response a little you can tweak it to this:
return response()->view('my/view, ['data'], 404, ['headers']);
Some code takes advantage of the ability to pass an array of views, and return the first one that exists.
return view()->first(['my/view1', 'my/view2'], ['data']);
It would be nice to be able to manipulate the response status and headers, but also use the view first functionality.
I'm proposing allowing
return response()->view(['my/view1', 'my/view2'], ['data'], 404, ['headers']);
If we're uncomfortable adding some magic to this method, I also considered making it a separate method on the ResponseFactory so it would be called as:
return response()->viewFirst(['my/view1', 'my/view2'], ['data'], 404, ['headers']);
which I could switch to.
I was also having trouble locating where tests are for this logic. If someone could point me in the right direction that would be appreciated.