Courses

Livewire 3 From Scratch: Practical Course

Pass Parameters to Component

Summary of this lesson:
- Passing static values to components
- Using dynamic values with colon syntax
- Implementing Route Model Binding
- Handling URL parameters

Passing data to a component is a common thing to do. Let's see how we can do that.


When rendering a Livewire component, we can pass a value to a property.

<livewire:create-post title="This is a title" />

Here we pass the initial title to the CreatePost Livewire component. We need to accept this in the components mount lifecycle hook.

class CreatePost extends Component
{
public string $title = '';
 
public function mount(string $title = null): void
{
$this->title = $title;
}
 
// ...
}

The mount method in Livewire is identical to the __construct used in PHP classes.

If you need to pass dynamic values or variables to a...

The full lesson is only for Premium Members.
Want to access all 30 lessons of this course? (108 min read)

You also get:

  • 73 courses
  • Premium tutorials
  • Access to repositories
  • Private Discord