Skip to content

Laravel package to auto-generate routes from static blade view.

License

Notifications You must be signed in to change notification settings

jornatf/laravel-route-generator

Repository files navigation

Laravel Route Generator

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

A Laravel package to auto-generate routes from static blade view.

You can use this package to generated simple page that does not require processing in a controller.

If you like this package you can Buy me a Coffee ☕️

Installation

You can install the package via composer:

composer require jornatf/laravel-route-generator

You can publish the config file with:

php artisan vendor:publish --tag="laravel-route-generator-config"

This is the contents of the published config file:

return [
        
    /*
    |--------------------------------------------------------------------------
    | View base path
    |--------------------------------------------------------------------------
    |
    | Specify here the folder containing the blade views for the routes. This
    | base will not be in the URL.
    |
    */

    'view_base_path' => 'static',

    /*
    |--------------------------------------------------------------------------
    | URL prefix
    |--------------------------------------------------------------------------
    |
    | Here you can specify a URL prefix. By default the value is null.
    |
    */

    'url_prefix' => null,

    /*
    |--------------------------------------------------------------------------
    | Midlewares
    |--------------------------------------------------------------------------
    |
    | You can specify the middlewares that should be used for all automatically
    | generated URLs.
    |
    */

    'middlewares' => [],
];

Usage

To start and depending on the configurations, you must create in resources\views, the folder with the same name as the value of view_base_path (default: static).

Then you'll have:

resources/
├─ views/
│  ├─ static/
│  │  ├─ about.blade.php
│  │  ├─ contact.blade.php

Here the routes will be generated:

Method URL Route name
GET /about static.about
GET /contact static.contact

You can then check the generation of the routes with the Artisan command:

php artisan generated-route:list

Prefix

You can add prefix to your route group in the config file, like this:

'url_prefix' => 'my_prefix',

Middlewares

You can add middlewares to your route group in the config file, like this:

'middlewares' => ['auth:sanctum'],

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.