Model binding
The standard form component expects an Eloquent Model
instance via the mount_form($model)
method.
It can either be a new Model
instance or an existing one.
public function mount(?SomeEloquentModel $model) {
$this->mount_form($model);
}
Examples
In a view
blade
<livewire:some-component :model="$some_model" />
component
public function mount($model) {
$this->mount_form($model);
}
Route model binding
Using Livewire route, full-page components web.php
Route::get('/user/{user}', UserForm::class);
component
public function mount(User $user) {
$this->mount_form($user);
}
Optional model binding
Using Livewire route, full-page components web.php
Route::get('/user/{user?}', UserForm::class);
component
public function mount(?User $user) {
//Laravel automatically creates a new User if none is passed in the route
$this->mount_form($user);
}
Last updated
Was this helpful?