This is the documentation for
You can switch versions in the menu on the left/at the top.
Check your current version with the following command:
composer show spatie/laravel-data
Livewire is a full-stack framework for Laravel that makes building dynamic interfaces simple without leaving the comfort of Laravel.
Laravel Data works excellently with Laravel Livewire.
You can use a data object as one of the properties of your Livewire component as such:
class Song extends Component
public SongData $song;
public function mount(int $id)
$this->song = SongData::from(Song::findOrFail($id));
public function render()
A few things are required to make this work:
- You should implement
Wireable on all the data classes you'll be using with Livewire
- Each of these classes should also use the
WireableData trait provided by this package
- That's it
We can update our previous example to make it work with Livewire as such:
class SongData extends Data implements Wireable
public function __construct(
public string $title,
public string $artist,