What seems to be the problem:
This is my very first livewire form and I have an issue using model binding. I have a one-to-many polymorphic relation on this model. I am editing a piece of content that can be either an article, a poll, an activity, …
I pass the content model to livewire, collect the extra data in livewire, and expect the fields to populate using the model binding syntax but the fields stay blank.
Steps to Reproduce:
Are you using the latest version of Livewire:
version 2.2
Do you have any screenshots or code examples:
This is what I currently have for the form to work
public function mount($action, $content)
{
$this->current_user = auth()->user();
$this->content = $content;
if ($action == 'edit')
{
$this->title = $this->content->contentable->title;
$this->lead = $this->content->contentable->lead;
$this->body = $this->content->contentable->body;
}
}
{!! Form::text('title', null, array('placeholder' => 'Title','class' => 'form-control', 'maxlength' => 255, 'wire:model.lazy' => 'title')) !!}
If I change the mount function to the code below, it does not work
public function mount($action, $content)
{
$this->current_user = auth()->user();
$this->content = $content->contentable;
How to fix this?