Sebastian Faltoni Software Architect. Passionate about Clean Code, Tech, Web, AI, .NET, Python, IOT, Swift, SwiftUI and also Blazor

Laravel Livewire Property is not loaded when fill is used

33 sec read

If you are using Laravel Livewire, and on your component your are trying to load properties from your eloquent model using fill, for example let’s say you have the following code inside your mount method.

$this->fill(Listing::whereId($listing_id)->first());

And one or more of your properties are not shown in your UI, your should check if you have hide them using hidden in your eloquent model for example

protected $hidden = [
    "user_id",
    "taxonomy_id"
];

For make these property works with fill you just have to make them visible for this purpose as follow.

$this->fill(Listing::whereId($listing_id)->first()->makeVisible(["taxonomy_id", "user_id"]));

This you way you can load and work with your properties values, but have them hidden by default, so if for example your are serialising this models on a REST API, you don’t have to worry that they are shown in the json output.

Sebastian Faltoni Software Architect. Passionate about Clean Code, Tech, Web, AI, .NET, Python, IOT, Swift, SwiftUI and also Blazor

Getting started with your first Laravel 8 and Jetstream…

Requirements NodeJS last version PHP Composer Introduction I’ve been programming for more than 20 years, mostly with .NET. Recently I had to work on...
Sebastian Faltoni
7 min read

Laravel Unique Validation rule on update has already been…

You got the validation rule with unique working on create, but when you are trying to update the same record your get The name...
Sebastian Faltoni
36 sec read

Leave a Reply

Your email address will not be published. Required fields are marked *