Blind Fish
Blind Fish

Reputation: 998

Laravel view:make issue with child view

Apologies if this is remedial. I am new to Laravel and honestly, my layout game is very weak. Here's the situation. I have a master layout in app.blade.php. That works fine. I then took out the content portion of the welcome page and threw that in a separate view as welcome.blade.php, which I call from a @yield. Works perfectly. However, that welcome file is still very long and I'd love to break it out into sections and include separate views for each section. In a non-Laravel world this would be as simple as

<?php include('firstsection.php'); ?>

Not so much in Laravel, and after much searching and tinkering I feel as if I'm getting further from the right answer. What I've done is to break out that first section as firstsection.blade.php, and place that file in the views folder of the resources folder. I am then trying to call that with

<?php echo View::make('view.firstection') ?>

This, and several different version of this such as appendend .blade.php to the view name, all give me View Not Found errors. I've looked through a ton of questions here and I guess the answer is just lost on me. Can anyone offer some advice?

Upvotes: 0

Views: 368

Answers (1)

Marcin Nabiałek
Marcin Nabiałek

Reputation: 111859

What you need here is @include directive to include partials of your layout. So in your Blade template you can do:

@include('firstsection')

to divide master view into smaller views.

You can read more at Control structures - Including Sub-Views section

EDIT

All views are by default relative to resources/views directory by default,

If you have file resources/views/test.blade.php to include it you simply use

@include('test')

and when you have file resources/views/search/test.blade.php to include it you should use:

@include('search.test')

You use here . as directory separator

Upvotes: 1

Related Questions