Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Daniel-Pablo's avatar

livewire properties to component dot notation error

Hi, I am doing the following -> inside a livewire component and laravel of course

    public $post;
    public $postArray;

    public function mount(Post $post)
    {
        $this-> post = $post;
        $this-> postArray = $post->toArray();
    }

as you can see I have to define the same thing passing it toArray()... to use dot notation wire:model="postArray.title" This way it works

but I don't want that, I don't want to convert this toArray, is there any way to get the property title just from the MODEL not converting it toArray();

thanks in advance for your help

0 likes
6 replies
LaryAI's avatar
Level 58

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.

Daniel-Pablo's avatar

my code is the same

public $post;

public function mount(Post $post)
{
    $this->post = $post;
}

public function save()
{
    $this->post->save();
}

is not working, as I explained , dot notation can only used with ARRAYS, but I don't understand why on the docs and the A.I Robots keep saying that this is the way.... what I am doing wrong?... thanks in advance of your help post.title that's what is not working at all on the call, until I convert the model to array

Endocrine's avatar

@Daniel-Pablo I have the same problem and do not understand this. I'll just reply here in hopes someone will answer at some point in time. For now I'll use a workaround but even Laravel Idea is suggesting the dot notation

Endocrine's avatar

@webrobert Hi thanks for the reply. I am using Livewire 3 and this is my code:

 <form
            class="flex flex-col bg-cp-dark-blue drop-shadow-cp-text justify-start rounded-xl px-4 py-5 gap-6
border-cp-white border relative z-20 max-h-fit w-full max-w-screen-md "
            wire:submit.prevent="onSubmit">
            <div class="flex flex-col gap-1">
                <label for="name">
                    Name
                </label>
                <input wire:model.live="protocol.name" type="text" name="name" id="name"
                    class="bg-cp-blue/50 rounded p-1" />
                @error('protocol.name')
                    <span class="text-cp-red text-xs">{{ $message }}</span>
                @enderror
            </div>
.
.
.
yabdab's avatar

If using v.3+ you also need to edit the config ...

However, because this behavior is so heavily relied upon in Livewire applications, version 3 maintains support for this behavior via a configuration item in config/livewire.php:

'legacy_model_binding' => true,

Please or to participate in this conversation.