There are many threads dealing with sub-views, with many various answers. And I didn't really find a matching answer, although I guess my pattern is quite usual:
A page displays results from a query. The results area can be updated with Ajax by user interactions. Therefore, I have two controllers:
pageDisplay
, which renders the overall view (without the results)resultsDisplay
, which generates and renders the results using a sub-view
My question deals with the initial display of the results with default settings. How can I call the resultsDisplay
controller from the pageDisplay
?
There are a couple of options I can't (or don't want to) use:
- An initial Ajax request, as this solution is not efficient considering SEO
- Including the sub-view using
@include
as the main view does not know the appropriate variables to send to the sub-view. Those variables are generated by theresultsDisplay
controller - Duplicating the code of the
resultsDisplay
controller into thepageDisplay
controller. This is so ugly and harder to maintain...
Maybe I could call the sub-controller from the main one. But I don't know how to do that since the sub-controller returns a view...
Thanks for your kind assistance!
I think what you're after is
nest()
to nest a child view. Here's an example:Then in your
pageDisplay
view you would simply echo out the nested view:And in your child view you could use the
$foo
and$bar
variables you've passed through.Check out the official docs (under Passing A Sub-View To A View) here: http://laravel.com/docs/responses#views