oddvalue / laravel-db-router
Routing through the database in Laravel
Requires
- php: ~7.3
- laravel/framework: ~6
- oddvalue/link-builder: ^1.0
Requires (Dev)
- codedungeon/phpunit-result-printer: ^0.27.0
- orchestra/testbench: ^4.0
- phpunit/phpunit: >=7.0
- squizlabs/php_codesniffer: ^3.5
This package is auto-updated.
Last update: 2024-11-12 05:21:36 UTC
README
This package is a work in progress and is not production ready.
This package allows you to set up dynamic routes for Laravel models in the database.
Features include:
- Automatically generate and store URLs for models in the database for dynamic routing.
- Remember old URLs and 301 redirect to the current one.
- Store multiple URLs with one as the main, canonical.
- Automatically update child page URLs when a parent's is updated.
Requirements
- PHP >= 7.3
- Laravel >= 6.x
- oddvalue/link-builder >= 1.0.0
Install
Via Composer
composer require oddvalue/laravel-db-router
Publish and migrate
php artisan vendor:publish --provider "Oddvalue\DbRouter\DbRouterServiceProvider"
php artisan migrate
Usage
Preparing Your Model
In order to use this package your model must implement the \Oddvalue\DbRouter\Contracts\Routable
interface.
Optionally, you may use the \Oddvalue\DbRouter\Traits\HasRoutes
trait to handle most of the interface implementation for you. Using the trait requires your model to have a getRouteGeneratorClass
method that returns the fully qualified class name of the generator class for setting up the routes.
Route Generators
The route generator class is responsible for getting the URLs that a model is accessible from and what controller action should be performed when that URL is hit. Generators must implement the \Oddvalue\DbRouter\Contracts\RouteGenerator
interface. There is also a \Oddvalue\DbRouter\Contracts\ChildRouteGenerator
interface. Once implemented this will allow the package to also generate and update routes for child pages of your model.
Using The Link Builder Package
The default implementation of the route generator uses oddvalue/link-builder to generate
Change log
Please see CHANGELOG for more information on what has changed recently.
Testing
$ composer test
Contributing
Please see CONTRIBUTING and CODE_OF_CONDUCT for details.
Security
If you discover any security related issues, please email jim@oddvalue.co.uk instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.