giuga/laravel-ordered-routes

Set order for routes defined in web.php

v1.0.5 2019-02-20 22:34 UTC

This package is auto-updated.

Last update: 2024-11-15 04:19:41 UTC


README

Add order to routes

Install the package

composer require giuga/laravel-ordered-routes

Change the default application loaded in bootstrap/app.php

Find

$app = new \Illuminate\Foundation\Application(
    realpath(__DIR__.'/../')
);

Replace with

$app = new \Giuga\Application(
    realpath(__DIR__.'/../')
);

Change the default Route alias in config/app.php

Find

'aliases' => [
...
'Route' => Illuminate\Support\Facades\Route::class,
...

Replace with

'aliases' => [
...
'Route' => Giuga\Routing\Facades\OrderRoute::class,
...

routes/web.php

By using this package you have the ability to define routes in what ever order you want.

In the example below the {slug?} would catch also the home route even if this was not our intention. By defining an order, if the requested url matches a predefined route like /home and /home does not have a higher order number than {slug?} home will be used.

Route:get('{slug?}', function($slug){ return $slug; } )->name('named.slug')->order(999);
Route:get('/home'), function(){ return 'This is my Home'; })->name('home');