oddvalue/laravel-db-router

Routing through the database in Laravel

dev-master / 1.0.x-dev 2020-05-11 18:55 UTC

This package is auto-updated.

Last update: 2024-04-12 03:59:36 UTC


README

This package is a work in progress and is not production ready.

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

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

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.