@extends
Declares the layout a child view inherits, filling its sections with the child's content.
@extends('layouts.app')Parameters
| Parameter | Type | Description |
|---|---|---|
$view | string | Dot-notated name of the layout view the current view inherits. |
Return value
Nothing — the named layout is rendered after the child view finishes, with the child's sections substituted in.
Errors
Extending a layout that does not exist throws InvalidArgumentException ("View [name] not found.") when the child view is rendered.
@extends names the layout a view inherits. The child then supplies content through @section blocks, which the layout places with @yield. This is Blade's template inheritance, the primary way to build layouts before components arrived; it is still fully supported and still what most existing applications use.
How to write the child
Put @extends on the first line, and put every piece of output inside a @section. Blade renders the child first, collecting sections, then renders the parent. Anything you write outside a section is echoed before the layout's HTML — that is where a stray comment or a debug line ends up appearing above the <!DOCTYPE>.
What trips people up
A view can extend only one layout; a second @extends silently wins over the first. Layouts nest by extending each other instead, which is how a section defined two levels down still reaches the top.
@extends and components do not mix well in one file: a view either inherits a layout or renders an <x-layout> component with a $slot. Pick one convention per application rather than per page.
Example
<?php
// resources/views/layouts/app.blade.php
$layout = <<<'BLADE'
<html>
<head>
<title>App Name - @yield('title')</title>
</head>
<body>
@section('sidebar')
This is the master sidebar.
@show
<div class="container">
@yield('content')
</div>
</body>
</html>
BLADE;
// resources/views/child.blade.php
$child = <<<'BLADE'
@extends('layouts.app')
@section('title', 'Page Title')
@section('content')
<p>This is my body content.</p>
@endsection
BLADE;
echo view('child')->render();
// <html><head><title>App Name - Page Title</title></head>
// <body>This is the master sidebar.<div class="container">
// <p>This is my body content.</p></div></body></html>When to use it
- Give every page in an admin panel the same chrome, nav and footer
- Add a print-specific layout that extends the main layout and overrides one section
- Migrate a legacy application page by page while both layout styles coexist
Frequently asked questions
Where does @extends go in a Blade view?
On the first line of the child view. Blade renders the child before the layout, so any markup placed outside a @section is echoed ahead of the layout's HTML.
Can a Blade view extend more than one layout?
No — a view inherits exactly one layout. To share chrome across several layouts, have one layout extend another and chain the sections upward.
What is the difference between @extends and @include?
@extends inverts control: the child names a layout that wraps it and pulls in its sections. @include renders another view inline at the point where you write the directive.
More examples
Nesting layouts
Because a view may extend only one layout, shared chrome is composed by chaining: the page fills content, the admin layout wraps it and fills body, and the base layout yields body. Each level only needs to know about the level directly above it.
<?php
// resources/views/layouts/base.blade.php
$base = <<<'BLADE'
<html>
<body>
@yield('body')
</body>
</html>
BLADE;
// resources/views/layouts/admin.blade.php — a layout that extends a layout
$admin = <<<'BLADE'
@extends('layouts.base')
@section('body')
<nav>Admin navigation</nav>
<main>@yield('content')</main>
@endsection
BLADE;
// resources/views/admin/users.blade.php
$page = <<<'BLADE'
@extends('layouts.admin')
@section('content')
<h1>Users</h1>
@endsection
BLADE;
echo view('admin.users')->render();Content outside a section leaks
The debug paragraph is rendered when the child view executes, which happens before the layout is rendered — so it lands ahead of the opening <html> tag rather than inside the page. Browsers usually recover, but the markup is invalid and anything relying on the doctype (quirks mode, some crawlers) behaves differently.
<?php
// resources/views/broken.blade.php
$broken = <<<'BLADE'
@extends('layouts.app')
<p>Debug: {{ $order->id }}</p>
@section('content')
<h1>Order</h1>
@endsection
BLADE;
echo view('broken', ['order' => $order])->render();
// <p>Debug: 42</p><html> ... </html>The component equivalent
Both produce the same page. The component form passes data as slots and attributes rather than through named sections, so the layout's inputs are visible at the call site. Laravel documents components as the modern approach, while @extends remains supported for the large amount of existing code written against it.
<?php
// Inheritance style
$inheritance = <<<'BLADE'
@extends('layouts.app')
@section('content')
<h1>Tasks</h1>
@endsection
BLADE;
// Component style: resources/views/components/layout.blade.php holds {{ $slot }}
$component = <<<'BLADE'
<x-layout>
<x-slot:title>Tasks</x-slot>
<h1>Tasks</h1>
</x-layout>
BLADE;
echo view('tasks')->render();
Discussion