0

What is the difference between @yield and @include in laravel?

i can't understand the possible difference between @yield and @include

28th Apr 2018, 3:00 AM
Rafid
2 Réponses
+ 1
This isn't a laravel thing, but a PHP thing. include is used to include another PHP file in the current files code. yield is used with generators. The @ symbol is the error control operator. It is used to suppress error messages.
28th Apr 2018, 3:46 AM
ChaoticDawg
ChaoticDawg - avatar
0
@yield is mainly used to define a section in a layout. When that layout is extended with @extends, you can define what goes in that section with the @section directive in your views. The layout usually contains your HTML, head, body, header and footers. You define an area (@yield) within the layout that your pages which are extending the template will put their content into. In your master template you define the area. For example: <body> @yield('content') </body> Lets say your home page extends that layout @extends('layouts.app') @section('content') // home page content here @endsection Any HTML you define in the content section on your homepage view in the 'content' section will be injected into the layout it extended in that spot. @include is used for reusable HTML just like a standard PHP include. It does not have that parent/child relationship like @yield and @section.
14th Aug 2018, 6:28 PM
Vipul Walia
Vipul Walia - avatar