Perhaps is this what you need ?
https://livewire.laravel.com/docs/nesting#binding-to-child-data-using-wiremodel
Something that was possible with Livewire V2 was updating a property of a model instance attached to a parent blade file (ie. non-livewire component) from a nested Livewire component.
In other words you could have a livewire component called EditPost, and have it included in your blade file like so:
#Livewire V2
PostController.php file
class PostController extends Controller
{
public function edit(Post $post)
{
return view('edit-post', [
'post' => $post,
]);
}
}
edit-post blade file
...
<livewire:edit-post-name :post="$post" />
...
EditPostName.php
class EditPost extends Component
{
public Post $post;
public function mount(Post $post)
{
$this->post = $post;
}
public function render()
{
return view('edit-post-name');
}
public function updateName()
{
$this->post->name = 'updated name';
}
}
edit-post-name.blade.php
<x-form.button wire:click="updateName()">Update</x-form.button>
<input type="text" wire:model.live="post.name"/>
When we run the above and pass in an existing post object, and click the Update button, we see the contents of the input change to read Update as expected.
However, when we submit the form on the view edit-post.blade.php (the parent), the updated ->name attribute is not passed in to the update route on the controller.
More specifically, it is passed back, but the value is always null:
public function updateRequest $request, Post $post)
{
dd('name', request()->name);
}
output
"name" // app/Http/Controllers/PostController.php:114
null // app/Http/Controllers/PostController.php:114
However, downgrading Livewire to V2 fixes this behaviour and the updated name field is passed back correctly to the update route.
Does anyone have any ideas on how to make this work in Livewire V3, or is this behaviour no longer supported in V3? The documentation seems to suggest this is still supported (https://livewire.laravel.com/docs/components#rendering-components) but perhaps I have misread it.
If anyone has any better alternatives for how to update the model instance in the blade view from an included livewire component that would be great too.
Please or to participate in this conversation.