aldrumo / route-loader
Laravel based route loader for use with sluggable items
0.2.1
2022-08-16 14:56 UTC
Requires
- php: ^7.3|^8.0
- illuminate/support: ^8.0|^9.0
Requires (Dev)
- orchestra/testbench: ^6.0
- phpunit/phpunit: ^9.0
- squizlabs/php_codesniffer: ^3.5
README
Laravel package for loading dynamic sluggable routes.
Setup
Create class that implements \Aldrumo\RouteLoader\Contracts\RouteLoader
.
This should return a collection that contains items with a slug
and id
attribute. This will likely be "Page" models.
<?php namespace App\Routes; use Aldrumo\RouteLoader\Contracts\RouteLoader; use App\Models\Page; use Illuminate\Support\Collection; class FilledRouteLoader implements RouteLoader { public function getRoutes(): Collection { return Page::where('is_active', true)->get(); } }
Register this to the container in your app service provider.
use Aldrumo\RouteLoader\Contracts\RouteLoader; use App\Routes\PageRouteLoader; $this->app->bind( RouteLoader::class, PageRouteLoader::class );
Generator
Place the following lins in the "boot" method of your apps service provider
use Aldrumo\RouteLoader\Generator; use Illuminate\Support\Facades\Route; Route::middleware('web') ->group( function () { $this->app[Generator::class]->generateRoutes(); } );
Clearing Routes
resolve(\Aldrumo\RouteLoader\Generator::class)->clearRoutes();
php artisan aldrumo:clear-routes