When we create a laravel based project, then of course we need a master layout file. We make different files for the header, footer, and sidebar also. In this example, I will discuss how to create master layout in laravel 9. This laravel layouts is a must needed things for laravel developers. So let's see how we can create laravel layout header footer.

Laravel provides the @yield() blade directive and @section blade directive to create a master layout file in Laravel. First, we have to create a master layout file and then every time we have to extend it using the @extends() blade directive. Let's see the example:


<!doctype html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="csrf-token" content="{{ csrf_token() }}">
    <title>{{ config('app.name', 'Laravel') }}</title>
    <div id="app">
        <nav class="navbar navbar-expand-md navbar-light bg-white shadow-sm">
            <div class="container">
                <a class="navbar-brand" href="{{ url('/') }}">
                <div class="collapse navbar-collapse" id="navbarSupportedContent">
                    <!--Header section -->
        <!--Content section -->
        <main class="py-4">


And now if we want to create a file that will be extended by the master file, then see the below example file:



<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header">{{ __('Dashboard') }}</div>

                <div class="card-body">
                    <!-- Page content -->


Read also: How To Create Custom Blade Directives In Laravel?



I have tried to discuss the clear concept of laravel layouts. Now we know how to create master layout in laravel. Hope this laravel blade template layout example tutorial will help you.