LaraLand's avatar

What's the difference between @include and @yield????

I'm having trouble with the @include and @yield... I slightly understand the difference but not clearly. so.. can somebody help me??

0 likes
3 replies
jlrdw's avatar

@include is for including another whole view within a view.

@yield is content for that the view, say a table in a div, a simple hello world or whatever.

3 likes
Snapey's avatar
Snapey
Best Answer
Level 122

@include is the same concept as a php include, get the named file and insert it at this point in the document.

@yield is more complicated but still quite simple.

When you load a view, eg 'home', at the start of the file it might declare that it extends a master layout.

At this point, control transfers to the master layout and the content from the master is output until you reach a @yield (like 'give way'). Now, control switches to a named section in the original view, until the end of the section, when it then reverts back to the master again

//    Welcome blade                   Master blade
//    
//    extend master  ------------------>
//                                    content
//                                    content
//                                    content
//                                    @yield ('body')
//       <------------------------------
//    @section 'body'
//    content
//    content
//    content
//    @end section
//       ------------------------------>
//                                    content
//                                    content
//                                    content
5 likes

Please or to participate in this conversation.