bastinald / laravel-livewire-routes
Laravel Livewire full page component routing.
Installs: 1 576
Dependents: 3
Suggesters: 0
Security: 0
Stars: 26
Watchers: 2
Forks: 8
Open Issues: 3
Requires
- laravel/framework: ^8.0
- livewire/livewire: ^2.0
README
This package allows you to specify routes directly inside your full page Livewire components via a route
method. The route
method returns the Laravel Route
facade, giving you complete control.
Documentation
Installation
Require the package via composer:
composer require bastinald/laravel-livewire-routes
Usage
The Route Method
Declare a route
method in your full page Livewire components to route to them:
namespace App\Http\Livewire\Auth; use Illuminate\Support\Facades\Route; use Livewire\Component; class Login extends Component { public function route() { return Route::get('login') ->name('login') ->middleware('guest'); } public function render() { return view('livewire.auth.login'); } }
As you can see, the route
method returns the Laravel Route
facade, so you can specify anything you normally would in a routes file with this method.
Using Route Parameters
Pass route parameters to the component mount
method as usual:
namespace App\Http\Livewire\Users; use App\Models\User; use Illuminate\Support\Facades\Route; use Livewire\Component; class Update extends Component { public $user; public function route() { return Route::get('users/update/{user}') ->name('users.update') ->middleware('auth'); } public function mount(User $user) { $this->user = $user; } public function render() { return view('livewire.users.update'); } }
Yes, this even works with automatic model binding!