Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bastinald/laravel-livewire-routes
Laravel Livewire full page component routing.
https://github.com/bastinald/laravel-livewire-routes
component laravel laravel-livewire livewire livewire-components php routing
Last synced: 2 months ago
JSON representation
Laravel Livewire full page component routing.
- Host: GitHub
- URL: https://github.com/bastinald/laravel-livewire-routes
- Owner: bastinald
- Created: 2021-04-26T04:46:42.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-09-10T00:10:51.000Z (over 3 years ago)
- Last Synced: 2024-04-25T19:01:07.727Z (8 months ago)
- Topics: component, laravel, laravel-livewire, livewire, livewire-components, php, routing
- Language: PHP
- Homepage:
- Size: 9.77 KB
- Stars: 25
- Watchers: 2
- Forks: 7
- Open Issues: 3
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# Laravel Livewire Routes
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](#installation)
- [Usage](#usage)
- [The Route Method](#the-route-method)
- [Using Route Parameters](#using-route-parameters)## Installation
Require the package via composer:
```console
composer require bastinald/laravel-livewire-routes
```## Usage
### The Route Method
Declare a `route` method in your full page Livewire components to route to them:
```php
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:
```php
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!