Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ChrisF79's avatar

Blade templates. Do I use <x-whatever> and $slot or @yield and @section?

I've been watching various tutorials about Blade layouts in Laravel 12 and I recently started watching the "30 Days to Learn Laravel" course here on Laracasts. All of hte other tutorials I watch utilize @section and @yield tags. The Laracast course teaches <x-whatever></x-whatever> and $slot.

I assume that both ways work but is there a preferred way? I don't want to start working on my site only to realize something is deprecated or not the right way of doing things any longer.

Any advice?

0 likes
2 replies
LaryAI's avatar

Great question! Both approaches—using @section/@yield and Blade components (<x-whatever> and $slot)—are valid and fully supported in Laravel 12. Here’s a breakdown to help you decide which to use:

1. @section and @yield

This is the traditional way to define layouts in Blade. You create a base layout and use @yield to define sections that child views can fill with @section.

Example:

layouts/app.blade.php

<!DOCTYPE html>
<html>
<head>
    <title>@yield('title')</title>
</head>
<body>
    @yield('content')
</body>
</html>

home.blade.php

@extends('layouts.app')

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

@section('content')
    <h1>Welcome Home!</h1>
@endsection

Use cases:

  • Great for simple layouts and when you want to define large sections of content.
  • Familiar to many Laravel developers.

2. Blade Components (<x-whatever> and $slot)

Blade components are more modern and encourage reusable, encapsulated UI pieces. You can pass data and content via attributes and slots.

Example:

resources/views/components/layout.blade.php

<!DOCTYPE html>
<html>
<head>
    <title>{{ $title ?? 'Default Title' }}</title>
</head>
<body>
    {{ $slot }}
</body>
</html>

home.blade.php

<x-layout title="Home Page">
    <h1>Welcome Home!</h1>
</x-layout>

Use cases:

  • Ideal for reusable UI elements (alerts, cards, buttons, etc.).
  • Encourages component-driven development.
  • Easier to nest and compose layouts.

Which Should You Use?

  • Neither is deprecated—both are fully supported.
  • For new projects, Blade components are generally recommended, especially for reusable UI and layouts. They offer better encapsulation and flexibility.
  • For simple layouts or legacy projects, @section/@yield is still perfectly fine.

In summary:
If you’re starting fresh, lean towards Blade components (<x-layout>, $slot, etc.), as they align with modern Laravel practices and make your code more maintainable and reusable. But don’t worry—both approaches are valid and will continue to be supported.

Let me know if you want more code examples or have a specific use case in mind!

Tray2's avatar
Tray2
Best Answer
Level 73

Section and yield are a bit older syntax, and isn't really components, they are more for layouts, and they really aren't that reusable. A component on the other hand is reusable, and it can have a matching class if more complex logic is needed.

I would recommend using components, that way it will not be hard for you to something like livewire.

1 like

Please or to participate in this conversation.