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

Single-File Components in Livewire v4: The View-First Approach

Learn how to create single-file components with the new .wire.php extension.

1 February 20261 min readLivewireاقرأ بالعربية

On this page

  1. File Location
  2. Basic Structure

Livewire v4 introduces a view-first approach where PHP logic and Blade markup coexist in a single file.

File Location

resources/views/components/counter.wire.php

Basic Structure

php
@php
new class extends Livewire\Component {
    public $count = 0;
    
    public function increment() {
        $this->count++;
    }
}
@endphp

<div>
    Count: {{ $count }}
    <button wire:click="increment">+</button>
</div>
All articles

Keep reading

  • Authorization in Livewire v4 Components1 February 20261 min read
  • Blaze Pre-Compiler: Massive Performance Gains in Livewire v41 February 20261 min read
  • Building a Bookmark Feature with Livewire v41 February 20261 min read