Laravel:blade Components And Layouts

Compose UIs with Blade components, slots, and layouts; keep templates pure and testable

jpcaparas Updated

File contents

Blade Components and Layouts

Encapsulate markup and behavior with components; prefer slots over includes.

Commands

sail artisan make:component Alert              # or: php artisan make:component Alert

// Use component
<x-alert type="warning" :message="$msg" class="mb-4" />

// Layouts + stacks
@extends('layouts.app')
@push('scripts')
    <script>/* page script */</script>
@endpush

Patterns

  • Keep components dumb: pass data in, emit markup out
  • Use merge() to honor passed classes/attributes in components
  • Prefer named slots for readability
  • Extract small, reusable atoms rather than giant organisms
  • Laravel 13+: use the @fonts directive (with the Vite font plugin) in layout <head> to emit preload links and @font-face rules automatically; @fonts(["sans", "mono"]) for a subset

jpcaparas/superpowers-laravel/tree/main/skills/blade-components-and-layouts commit 473755b4a6

Frequently asked questions

npx skillmds@latest add jpcaparas/laravel-blade-components-and-layouts