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

Computed Properties in Livewire v4

Use computed properties for derived state.

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

On this page

  1. Usage
  2. In Blade Template

Computed properties cache expensive calculations.

Usage

php
use Livewire\Attributes\Computed;
use Livewire\Component;

class PostList extends Component
{
    public string $search = '';
    
    #[Computed]
    public function filteredPosts(): Collection
    {
        return Post::where('title', 'like', "%{$this->search}%")->get();
    }
}

In Blade Template

blade
@foreach($this->filteredPosts as $post)
    <div>{{ $post->title }}</div>
@endforeach
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