Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

DavidLoevy's avatar

How to use (sub)view in view

hi friends, I have in (my Laravel ver.4) application view "view02.blade.php" which it can call via URL (route): http://localhost/.../SomeRoute02 it is code in "route.php": Route::get('SomeRoute02','SomeController@SomeFunc02'); and code in "SomeController" is: public function SomeFunc02() { ... $ThatArray=DB::select('... $ThatOtherArray=... return View::make('view02', array('SomeArray'=>$ThatArray, 'SomeOtherArray'=>$ThatOtherArray)); } and I have similar view "view01.blade.php" which it can call via URL (route): http://localhost/.../SomeRoute01 Code in "route.php" is similar also: Route::get('SomeRoute01','SomeController@SomeFunc01'); as well as code in "SomeController": ... return View::make('view01', array('AnotherArray'=>$AnotherArray)); } Until now I call both views separately (via their URLs), but now I need call only one view and displays information of both.

And my question is: how can I include view02 into view01? Let view01 has own content as well as view02 has own?

0 likes
3 replies
DavidLoevy's avatar

hi, yes this solution is pretty good if my "view02" contains only simple text (or HTML data). But for this case - my "view02", is called by route:

localhost/.../SomeRoute02 

passed to "view02" some values:

return View::make('view02', array('SomeArray'=>$ThatArray, 'SomeOtherArray'=>$ThatOtherArray));

and in my "view02" these values are displayed as:

{{ $ThatArray->SomeParameter }}
{{ $ThatOtherArray->SomeOtherParameter }}

But if I include "view02" into "view01" on this way:

@include('view02')

error is raised:

Undefined variable: $ThatArray

and I cannot display these values in "view02" included within "view01".

MiguelBarros's avatar

Hi @DavidLoevy , when you do


@include('view02')

instead do


@include('view02', ['thatArray' => $thatArray, 'thatOtherArray' => $thatOtherArray])

1 like

Please or to participate in this conversation.