Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

Property Attributes: Locked, URL, Computed

Premium
4 min read

Livewire 3 was released with a few features using PHP Attributes on top of Component properties. In this lesson, let's look at them.


Locked Properties

Livewire properties can be modified on both the frontend and backend. Sometimes this could be a security breach if someone tries to change the input value in their browser console. To prevent it, we can lock public properties.

To lock a public property, you must add a #[Locked] attribute.

use Livewire\Attributes\Locked;
 
class ShowPost extends Component
{
#[Locked]
public int $id;
 
public function mount($postId): void
{
$this->id = $postId;
}
 
// ...
}

If you try to modify the $id property, Livewire will throw an Exception.

locked property exception

When using Model as a property, Livewire automatically will protect model's ID.

use App\Models\Post;
 
class ViewPost extends Component
{
public Post $post;
 
public function mount(Post $post): void
{
$this->post = $post;
}
 
// ...
}

Properties with URL Attribute

Sometimes you might want to store component's properties in the URL. For example, when building...

The Full Lesson is Only for Premium Members

Want to access all of our courses? (29 h 14 min)

You also get:

54 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

CL
Caribation Labs ✓ Link copied!

I have difficullty to understand why the comments() function wouldn't work without the #Computed attribute?

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.