Available Livewire 3 PHP Attributes

Available Livewire 3 PHP Attributes

Livewire 3 introduces a hand full of PHP attributes you can use in your components. So far there is no API reference in the new documentation, so here's a list of them from the source:


To create a computed property, you can add the #[Computed] attribute above any method in your Livewire component. Once the attribute has been added to the method, you can access it like any other property.

2public function user()
4 return User::find($this->userId);

Because the #[Computed] attribute has been added to the user() method, the value is accessible in other methods in the component and within the Blade template.


Sometimes there are actions in your component that don't need to communicate with the server and can be more efficiently written using only JavaScript.

In these cases, rather than writing the actions inside your Blade template or another file, your component action may return the JavaScript function as a string. If the action is marked with the #[Js] attribute, it will be callable from your application's frontend:

2public function reset()
4 return <<<'JS'
5 $wire.query = '';
6 JS;

Just like #[Js] methods, you can access the current component's $wire object inside the expression.


To use a different layout for a specific component, you can place Livewire's #[Layout] attribute above the component's render() method, passing it the relative view path of your custom layout:

2public function render()
4 return view('livewire.create-post');

Or if you prefer, you can use this attribute above the class declaration.


Livewire properties are able to be modified freely on both the frontend and backend using utilities like wire:model. If you want to prevent a property — like a model ID — from being modified on the frontend, you can use Livewire's #[Locked] attribute:

2public $id;


Livewire provides a #[Modelable] attribute you can add to any child component property to make it modelable from a parent component.

Below is the TodoInput component with the #[Modelable] attribute added above the $value property to signal to Livewire that if wire:model is declared on the component by a parent it should bind to this property:

3namespace App\Livewire;
5use Livewire\Component;
7class TodoInput extends Component
9 #[Modelable]
10 public $value = '';
12 public function render()
13 {
14 return view('livewire.todo-input');
15 }


To listen for an event in a Livewire component, add the #[On] attribute above the method you want to be called when a given event is dispatched:

2public function updatePostList($title)
4 // ...


By default, Livewire props are not reactive. When using Livewire, every component is an island. This means that when an update is triggered on the parent and a network request is dispatched, only the parent component's state is sent to the server to re-render - not the child component's.

But, if you want or need a prop to be reactive, you can easily enable this behavior using the #[Reactive] attribute parameter:

2public $todos;


Sometimes there might be an action in your component with no side effects that would change the rendered Blade template when the action is invoked. If so, you can skip the render portion of Livewire's lifecycle by adding the #[Renderless] attribute above the action method:

2public function incrementViewCount()
4 $this->post->incrementViewCount();


If you prefer to co-locate your component's validation rules with the properties directly, you can use Livewire's #[Rule] attribute:

2public $title = '';
5public $content = '';


If you have a full page component with the following HTML:

2 <title>{{ $title ?? 'Page Title' }}</title>

Then you can set that title from the component:

1#[Title('Create Post')]
2public function render()
4 return view('livewire.create-post');


Livewire allows you to store component properties in the URL's query string.

Property values are lost from page refreshes. To preserve the property value across page loads so that a visitor can refresh the page or share the URL, we can store the property value in the URL's query string by adding the #[Url] attribute above the property like so:

2public $search = '';

Initializing properties from the URL

You can set a default value by passing it to the query string:


2public $search = ''; // Will be set to "bob"...

Using an alias

You can specify a query string alias by providing the as parameter to the #[Url] attribute:

1#[Url(as: 'q')]
2public $search = '';

Now, when a user types "bob" into the search field, the URL will show: https://example.com/users?q=bob instead of ?search=bob.

Display on page load

If you want the ?search entry to always be included in the query string, even when the value is empty, you can provide the keep parameter to the #[Url] attribute:

1#[Url(keep: true)]
2public $search = '';

Now, when the page loads, the URL will be changed to the following: https://example.com/users?search=

Storing in history

To force Livewire to use history.pushState when updating the URL, you can provide the history parameter to the #[Url] attribute:

1#[Url(history: true)]
2public $search = '';

In the example above, when a user changes the search value from "bob" to "frank" and then clicks the browser's back button, the search value (and the URL) will be set back to "bob" instead of navigating to the previously visited page.

I'm hoping soon the new documentation will have an API reference like V2 did, but until then I hope this helps.

Anthony Rappa

By Anthony Rappa

Hello! I'm a full stack developer from Long Island, New York. Working mainly with Laravel, Tailwind, Livewire, and Alpine.js (TALL Stack). I share everything I know about these tools and more, as well as any useful resources I find from the community. You can find me on GitHub and LinkedIn.