Overview
The Livewire component system provides full server-side reactivity, allowing you to build dynamic interfaces without writing JavaScript. Components automatically sync state between server and client.Class: Lyger\Livewire\Component
Base class for all Livewire components with reactive properties and lifecycle hooks.
Creating a Component
Lifecycle Methods
mount()
Called when the component is first created.mixed
Optional parameters passed to the component
render()
Renders the component view. Must be implemented by all components.string
The rendered HTML of the component
Property Management
getPublicProperties()
Returns all public properties for JavaScript synchronization.array
Array of public property names and values
get()
Retrieves a protected property value.string
required
The property name
mixed
Default value if property doesn’t exist
set()
Sets a property value and tracks it for updates.string
required
The property name
mixed
required
The value to set
Method Calling
callMethod()
Executes a method on the component and returns effects.string
required
The method name to call
array
Parameters to pass to the method
array
Contains ‘effect’, ‘data’, or ‘error’ keys
Validation
validate()
Validates component properties against rules.array
required
Validation rules array
array
Custom error messages
array
Validated data on success
ValidationException
Thrown when validation fails
addError()
Manually adds an error message for a field.string
required
The field name
string
required
Error message
Events
emit()
Emits an event to other components.string
required
Event name
mixed
Event parameters (variadic)
emitUp()
Emits an event to parent components only.dispatchBrowserEvent()
Dispatches a custom browser event for JavaScript to listen to.string
required
Browser event name
array
Event data payload
Navigation
redirect()
Redirects to a URL.string
required
The URL to redirect to
redirectToRoute()
Redirects to a named route with parameters.string
required
Route name or pattern
array
Route parameters
refresh()
Refreshes the component.File Uploads
validateFile()
Validates an uploaded file.string
required
Form field name
array
required
Validation rules
Utility Methods
reset()
Resets component properties to default values.string
Specific properties to reset (variadic). If empty, resets all.
user()
Gets the currently authenticated user.array|null
User data array or null if not authenticated
isAuthenticated()
Checks if a user is authenticated.bool
True if authenticated, false otherwise
Traits
WithEvents
Provides event listener functionality.WithFileUploads
Provides file upload handling.WithPagination
Adds pagination functionality to components.nextPage(): Go to next pagepreviousPage(): Go to previous pagegotoPage(int $page): Jump to specific page
WithSearch
Adds search functionality with query filtering.The
updatingSearch() lifecycle hook automatically resets pagination to page 1 when search changes.Manager Class
Lyger\Livewire\Manager
Manages component registration and request handling.register()
Registers a component class.get()
Gets a component instance by name.handle()
Handles incoming Livewire AJAX requests.Request
required
The HTTP request object
Response
JSON response with component data