PHP code example of tanthammar / livewire-auto-routes

1. Go to this page and download the library: Download tanthammar/livewire-auto-routes library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tanthammar / livewire-auto-routes example snippets

 
use Tanthammar\LivewireAutoRoutes\HasGuestRoute;

class FooComponent extends \Livewire\Component
{
    use HasGuestRoute;
    
    protected string $guestRoute = '/foo/{id}/edit'; //route name becomes 'foo.id.edit'
}
 
use Tanthammar\LivewireAutoRoutes\HasAuthRoute;

class FooComponent extends \Livewire\Component
{
    use HasAuthRoute;
    
    protected string $authRoute = '/foo/{name?}'; //route name becomes 'foo.name'
}

use Illuminate\Support\Facades\Route;

class FooComponent extends \Livewire\Component
{
    public function route(): \Illuminate\Routing\Route|array
    {
        return Route::get('foo', static::class)
            ->middleware('auth') //default middleware is 'web'
            ->name('foo');
    }
}

use Tanthammar\LivewireAutoRoutes\RouteMaker;

class FooComponent extends \Livewire\Component
{
    public function route(): RouteMaker
    {
        return new RouteMaker(
            route: 'users/{id}/edit', //if you omit $name, this route name will become 'users.id.edit'
            middleware: ['auth:sanctum', 'verified'],
            component: static::class,
            name: 'users.edit' //OPTIONAL, else $name will be generated from $route
        );
    }
}