It seems like you want to bind a Livewire model property directly to an input without converting it to an array. You can achieve this by using the wire:model directive with the model property and the attribute you want to bind. However, you need to ensure that the property you're binding to is public and accessible.
Here's how you can modify your Livewire component to bind directly to the Post model's title attribute:
public $post;
public function mount(Post $post)
{
$this->post = $post;
}
public function save()
{
$this->post->save();
}
In your Livewire component's blade template, you can bind to the title property of the Post model like this:
<input type="text" wire:model="post.title">
This will automatically update the title property of the Post model in your Livewire component when the input changes.
Remember that when you bind a model property directly, any changes to the input will be reflected in the model, and you should handle saving the model to the database appropriately, for example, by calling a save method when a form is submitted.
Also, make sure that the property you are binding to (title in this case) is fillable in your Post model, or you have disabled mass assignment protection by setting the $guarded property to an empty array.
Here's an example of what your Post model might look like with the $fillable property set:
class Post extends Model
{
protected $fillable = ['title', 'content', ...];
}
Or with mass assignment protection disabled:
class Post extends Model
{
protected $guarded = [];
}
This should allow you to use the model's properties directly in your Livewire component without converting it to an array.