Installation:
composer require livewire/livewire alexsabur/orchid-livewire:^5.3
php artisan vendor:publish --tag=orchid-livewire-assets
Ensure you’re using a compatible Orchid version (12–14 for ^5.3).
First Use Case:
Convert an Orchid Table or Screen to Livewire by extending Orchid\Livewire\LivewireTable or Orchid\Livewire\LivewireScreen:
use AlexSabur\OrchidLivewire\LivewireTable;
class MyLivewireTable extends LivewireTable
{
public function columns(): array
{
return [
'id' => 'ID',
'name' => 'Name',
];
}
}
Register the component in routes/web.php:
Route::get('/livewire-table', \App\Livewire\MyLivewireTable::class);
Key Files:
app/Livewire/ – Store custom Livewire components.resources/views/vendor/orchid-livewire/ – Override default views (if published).Table Integration:
LivewireTable for CRUD tables with built-in pagination, sorting, and filtering.query() to customize Eloquent queries:
public function query(): Builder
{
return Model::query()->where('active', true);
}
withSearch() for global search:
public function columns(): array
{
return [
'name' => (new TextColumn('name'))
->withSearch()
->sortable(),
];
}
Screen Integration:
LivewireScreen for forms or dashboards:
class UserProfile extends LivewireScreen
{
public $name;
public function mount()
{
$this->name = auth()->user()->name;
}
public function updateProfile()
{
auth()->user()->update(['name' => $this->name]);
}
}
Input, Select) within Livewire templates.Hybrid Approach:
// In a Screen
public function render()
{
return view('livewire.my-component')
->layout('orchid::layouts.main');
}
Asset Management:
php artisan vendor:publish --tag=orchid-livewire-assets
resources/views/vendor/orchid-livewire/table.blade.php for table-specific changes.public function mount()
{
$this->authorize('view-dashboard');
}
Orchid\Platform\Dashboard) via constructor:
public function __construct(public Dashboard $dashboard) {}
$this->livewire(MyLivewireTable::class)
->assertSee('Expected Text');
Version Mismatches:
1.x → orchid-livewire:^3.011.x → orchid-livewire:^4.012–14 → orchid-livewire:^5.3
Fix: Clear vendor/ and node_modules/ if upgrading.Asset Conflicts:
orchid-livewire and livewire assets may duplicate Alpine.js.
Fix: Exclude one in webpack.mix.js or use mix.disableNotifications().Livewire State Persistence:
protected $persistent = true; in components needing session persistence.CSRF Token Issues:
VerifyCsrfToken excludes Livewire routes:
protected $except = [
'livewire/*',
];
wire:ignore on Orchid-specific elements (e.g., modals) to prevent reactivity conflicts.storage/logs/livewire.log for Livewire-specific errors.@debug($this) in Livewire templates to inspect component state.Custom Columns:
Extend AlexSabur\OrchidLivewire\Columns\Column for reusable column types:
class StatusColumn extends Column
{
public function render()
{
return view('livewire::columns.status', ['value' => $this->value]);
}
}
Event Handling: Listen to Orchid events within Livewire:
public function boot()
{
event(new \Orchid\Events\RegisteredUser());
}
API Endpoints:
Use Livewire’s wire:submit with Orchid’s API resources:
public function save()
{
$resource = new UserResource(auth()->user());
return response()->json($resource);
}
Localization:
Override translations in resources/lang/vendor/orchid-livewire/.
Example:
'livewire' => [
'actions' => [
'edit' => 'Custom Edit Text',
],
],
How can I help you explore Laravel packages today?