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

Dependency Injection in Livewire v4

Inject services into your Livewire components.

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

On this page

  1. In mount()
  2. In Actions
  3. Type-Hinted Properties

Livewire v4 supports dependency injection.

In mount()

php
public function mount(UserService $users): void
{
    $this->users = $users->all();
}

In Actions

php
public function save(PostRepository $repo): void
{
    $repo->create($this->form);
}

Type-Hinted Properties

php
public function boot(Logger $logger): void
{
    $logger->info('Component booted');
}
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