Components
LiVue components are PHP classes that define reactive state and actions, paired with Blade templates that use Vue directives for interactivity.
Basic Structure
A LiVue component consists of two parts: a PHP class and a Blade template.
app/LiVue/Counter.php
<?php
namespace App\LiVue;
use LiVue\Component;
class Counter extends Component
{
public int $count = 0;
public function increment()
{
$this->count++;
}
}
resources/views/livue/counter.blade.php
<div>
<p>Count: {{ count }}</p>
<button v-click:increment>
Add
</button>
</div>
Tip: Generate a new component with
php artisan make:livue Counter
Rendering Components
There are multiple ways to render a LiVue component in your views.
Blade Directive
@livue('counter')
@livue('counter', ['count' => 10])
Component Tag Syntax
<livue:counter />
<livue:counter :count="10" />
Full Page Component (routes/web.php)
use LiVue\Facades\LiVue;
LiVue::route('/counter', Counter::class);
Properties
Public properties on your component become reactive state, automatically synced between server and client.
class UserProfile extends Component
{
// Primitive types
public string $name = '';
public int $age = 0;
public bool $active = true;
// Arrays
public array $items = [];
// Eloquent models (auto-serialized)
public User $user;
// Collections
public Collection $users;
// Carbon dates
public Carbon $publishedAt;
}
Supported Types
- • Primitives (string, int, float, bool, array)
- • Eloquent Models & Collections
- • Carbon instances
- • Enums
- • Custom objects (via Synthesizers)
Property Attributes
- •
#[Guarded]- Prevent client modification - •
#[Url]- Sync with query string - •
#[Session]- Persist in session - •
#[Reactive]- Parent-child sync
Actions
Public methods become actions that can be called from the template.
PHP
public function save()
{
$this->validate();
$this->user->save();
}
public function delete(int $id)
{
Item::destroy($id);
}
Blade
<button v-click:save>
Save
</button>
<button v-click:delete="{{ item.id }}">
Delete
</button>
Quick Reference
| Feature | Syntax | Description |
|---|---|---|
| Call action | v-click:method |
Call server method on click |
| Two-way binding | v-model="property" |
Sync input with server state |
| Display data | {{ property }} |
Reactive text interpolation |
| Conditionals | v-if="condition" |
Conditional rendering |
| Loops | v-for="item in items" |
List rendering |
| Loading state | v-loading |
Show during AJAX |