Difference between @yield and @include in Laravel

@yield and @include look very similar and they serve almost the same purpose. Let’s see what are the differences between these two. We use @yield to define a section in a layout. You can define what should be placed in the section with @section when you extend the layout to other pages with @extend. The layout you define will contain the header, footer, head, body of HTML.

Example for @yield

<body>

     @yield('content')

</body>

@include is used like a PHP include. It is used for HTML that will be used again. It imports content of a different file into the file we want at the location in which it is placed.

Example of @include:

< some html or other script >

@include('include.file_name') // "include." indicates the subdirectory that the file is in.

< more html or other script >