Mahmoud Al-HabashOpen to new projects
  • WorkWork
  • ServicesServices
  • LabLab
  • WritingWriting
  • ContactContact
Amman--:--عربي
Writing/Laravel

Laravel Blade Components: Build Reusable UI

Create powerful reusable components with Laravel Blade.

16 January 20261 min readLaravelاقرأ بالعربية

On this page

  1. Create Component
  2. Component Class
  3. Component Template
  4. Usage

Build reusable Blade components:

Create Component

php artisan make:component Alert

Component Class

php
class Alert extends Component
{
    public function __construct(
        public string $type = 'info',
        public string $message = ''
    ) {}
}

Component Template

blade
<div class="alert alert-{{ $type }}">
    {{ $message }}
    {{ $slot }}
</div>

Usage

blade
<x-alert type="success" message="Saved!" />
All articles

Keep reading

  • Laravel Action Classes Pattern16 January 20261 min read
  • Laravel Action Classes: Single Responsibility16 January 20261 min read
  • Laravel API Rate Limiting16 January 20261 min read