What is Laravel Blade Components

There might have a lot of people ask, what is laravel blade component.

Patrick Wan
2 min readJun 13, 2021

--

Laravel Blade Components
Photo by Kevin Ku on Unsplash

Blade components are a subset of blade template that allow you to create new custom, reusable, encapsulated PHP and HTML.

For example you may want to create a layout to be used in many of your application pages. So you build your layout as a component and can reused the component wherever you want.

When created, component can be call with same syntax as any html tag:

<x-layout>
<x-slot>
</x-slot>
</x-layout>

Class based component

Class based component is compose of a php file that encapsulate component logic and a template file.

To create a class based component you can use the Artisan command make:component

php artisan make:component Layout

This command will create two files:

app\View\Components\Layout.php
resources\views\components\layout.blade.php

The Layout.php file is a class that inherits from Component

<?php

namespace App\View\Components;

use Illuminate\View\Component;

class Layout extends Component
{
public function __construct()
{
//
}

--

--

Patrick Wan
Patrick Wan

Written by Patrick Wan

My name’s Patrick. I’m a Software Developer, experience in Laravel, Vue Js, React Js, Livewire, Jquery, Codegniter, NPM, GIT. I have 5 years plus experience.