Laravel blade section directive example

Laravel provides many built-in directives. This directives helps in adding PHP codes and functionalities easily. One of these directives is @section and @yield directives.

In this article, I will show you how to use @section and @yield directives in Laravel blade. All web application uses common layout file which extends to all views.

In Laravel application, main Layout file contains @yield directives with name inside it. Here is the common layout view file at resources/views/layouts/app.blade.php.

<!DOCTYPE html>
        <title>@yield('title') - Laravel</title>
        <div class="container">

We have defined main layout view. Now we will extends this layout in any blade view. When we will add @section directive in blade view, It will be inserted to master view's @yield directive.


@section('title', 'Page Title')


    <p>This is appended to the master sidebar.</p>

    <p>This is my body content.</p>

I hope it will help you on your web developement. Thanks for giving time in reading article.