Giter VIP home page Giter VIP logo

route-priority's Introduction

Package to add priority to Laravel 5 routes

Latest Stable Version Total Downloads Latest Unstable Version License

Installation

  1. Add langaner/route-priority to composer.json.

    "langaner/route-priority": "dev-master"

2)Run composer update to pull down the latest version of the package.

3)Now open up app/config/app.php and add the service provider to your providers array.

Langaner\RoutePriority\RoutePriorityServiceProvider::class,

4)Add the trait to App\Http\Kernel

use \Langaner\RoutePriority\RouterTrait;

Usage

Change routes priority:

Route::get('test', ['uses' => 'Controller@showAction'])->setPriority(100);

Default Priority

Default priority is 50. Higher priority - values from 50 and above, lower priority - 49 and below.

Usage example

Route::get('/test/{slug}', …);
Route::get('/test/hello', …);

In this example second route will not work. Add priority 0 to the first route will fix the error:

Route::get('/test/{slug}', …)->setPriority(0);
Route::get('/test/hello', …);

Second route now has higher priority.

Group priority

You can put priority to groups:

Route::group(['prefix' => 'test-group', 'priority' => 10], function () {
	Route::get('/test/hello', function () {
	    return 'First group';
	});
});

Route::group(['prefix' => 'test-group', 'priority' => 20], function () {
	Route::get('/test/hello', function () {
	    return 'Second group';
	});
});

Second group has higher priority then First group. All routes in the group will has the same priority as the group.

route-priority's People

Contributors

langaner avatar sebastienheyd avatar snizhok avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.