laravel/blank-livewire-starter-kit
A blank Laravel + Livewire 4 starter kit with Tailwind for building reactive UIs in PHP. Ideal for Blade-first teams who want a modern foundation without JavaScript SPA complexity. No authentication scaffolding included.
Installation
composer create-project laravel/blank-livewire-starter-kit my-project
cd my-project
npm install && npm run dev # Install and build Tailwind assets
First Use Case: Create a Livewire Component Generate a new Livewire component with Blade scaffolding:
php artisan make:livewire Counter
This creates:
app/Livewire/Counter.php (PHP logic)resources/views/livewire/counter.blade.php (Blade template)Where to Look First
app/Http/Livewire/: Default namespace for Livewire components.resources/views/layouts/app.blade.php: Base layout with Tailwind directives.tailwind.config.js: Tailwind configuration (if customizing styles).webpack.mix.js: Asset compilation setup (if extending frontend).Component-Based Development
UserProfile, DashboardStats).// app/Livewire/UserProfile.php
public $name;
public function updateProfile() {
$this->validate(['name' => 'required']);
// Update logic...
}
<!-- resources/views/livewire/user-profile.blade.php -->
<input wire:model="name" type="text">
<button wire:click="updateProfile">Save</button>
Reusability with Props and Events
public $userId;
public function mount($userId) { $this->userId = $userId; }
$this->emit('userUpdated', $userId);
<script>
document.addEventListener('livewire:init', () => {
Livewire.on('userUpdated', userId => {
console.log(`User ${userId} updated!`);
});
});
</script>
State Management
public $search = '';
public function searchUsers() {
$this->users = User::where('name', 'like', "%{$this->search}%")->get();
}
wire:ignore for static DOM elements.Integration with Laravel Features
laravel/breeze or laravel/jetstream (not included by default).$this->dispatchBrowserEvent() for real-time updates:
$this->dispatchBrowserEvent('alert', ['type' => 'success', 'message' => 'Updated!']);
<script>
window.addEventListener('alert', event => {
toast.fire({ icon: event.detail.type, title: event.detail.message });
});
</script>
Testing
Livewire::test() in PHPUnit:
public function test_counter_increments() {
$component = Livewire::test(Counter::class);
$component->increment();
$component->assertSet('count', 1);
}
Tailwind Conflicts
@layer directives or incorrect build order.tailwind.config.js includes all necessary paths and run npm run dev after changes.Livewire Wire:Key Misuse
wire:key on dynamic components causes hydration errors.@foreach($items as $item)
<div wire:key="item-{{ $item->id }}">
{{ $item->name }}
</div>
@endforeach
State Persistence
Overusing Livewire for Static Content
wire:ignore for static sections or consider plain Blade.Debugging Tips
.env:
LIVEWIRE_LOG_LEVEL=debug
__livewire payloads.Custom Directives Extend Livewire’s JavaScript with custom directives (e.g., for animations):
// resources/js/livewire.js
document.addEventListener('livewire:init', () => {
Livewire.directive('fade', (el, { expression }) => {
el.style.transition = 'opacity 0.3s';
el.style.opacity = expression ? '1' : '0';
});
});
<div wire:fade="{{ $show }}">Content</div>
Middleware for Livewire Protect Livewire components with middleware:
// app/Http/Middleware/CheckRole.php
public function handle($request, Closure $next) {
if (!auth()->user()->isAdmin) {
abort(403);
}
return $next($request);
}
// app/Livewire/AdminDashboard.php
public function middleware() {
return [\App\Http\Middleware\CheckRole::class];
}
Hybrid Blade + Livewire Combine static Blade with dynamic Livewire:
<div class="static-content">
<!-- Plain Blade -->
<h1>Welcome, {{ auth()->user()->name }}</h1>
</div>
@livewire('dynamic-content', ['user' => auth()->user()])
Performance Optimization
wire:init for non-critical components:
@livewire('heavy-component', key('heavy-component'), only: ['mount'])
public $search;
protected $listeners = ['debouncedSearch' => 'searchUsers'];
public function updatedSearch($value) {
$this->dispatch('debouncedSearch')->after(500);
}
Configuration Quirks
php artisan vendor:publish --provider="Livewire\LivewireServiceProvider"
tailwind.config.js is configured for JIT mode if using @apply.How can I help you explore Laravel packages today?