In Livewire 2 it was common to use this code for model binding:
public Post $post;
protected $rules = [
'post.title' => 'required',
'post.description' => 'required',
];
<input wire:model="post.title">
<input wire:model="post.description">
doc: https://livewire.laravel.com/docs/upgrading#eloquent-model-binding
But now, in Livewire 3 I wanna to get this behaviour, documentation says that I can get this behavior via a configuration item in config/livewire.php:
'legacy_model_binding' => true,
But I wanna to be with Livewire 3 standarts and I wanna ask you how should I proceed now?
my code below:
public Recipe $recipe;
public function mount(Recipe $recipe)
{
$this->recipe = $recipe;
}
and my view:
<!-- Recipe name -->
<div>
<label>Recipe name</label>
<input wire:model="recipe.name"
name="recipe.name"
type="text"
placeholder="Chicken Broth"
/>
@error('recipe.name')
<span>{{ $message }}</span>
@enderror
</div>
and as expected, it doesn't work in Livewire 3
ChatGPT suggests use arrays (but I don't wanna rely only on gpt):
public $recipe_data = [];
public function mount(Recipe $recipe)
{
$this->recipe_data = [
'id' => $recipe->id,
'name' => $recipe->name,
'description' => $recipe->description,
'image' => $recipe->image,
];
}
I would be grateful for advice