laravel auto route
laravel General Route to allow You not to put every general route in the route file, (*1)
Installation
run this command composer require hosamaldeen/auto_route
, (*2)
Route Rules
there are 4 ways for general routes based on the count of the segments
* Urls that include 1 segments like /product
will request ProductController@index, (*3)
-
Urls that include 2 segments /product/all
will request ProductController@all, (*4)
-
Urls that include 2 segments and the second segment is number like /product/1
will request ProductController@view
and pass the value to the function as {id}, (*5)
-
Urls that include 3 segments /product/search/1
will request ProductController@search
and pass the value to the function as {id}, (*6)
Usage
in your route file add this, (*7)
$defaultRoute = new HosamAldeen\AutoRoute\Route;
$defaultRoute->create();
you can add some options to your routes, (*8)
$defaultRoute = new HosamAldeen\AutoRoute\Route;
$defaultRoute->prefix = '';
$defaultRoute->middleware = [];
$defaultRoute->namespace = '';
$defaultRoute->create();
Full Example
$defaultRoute = new HosamAldeen\AutoRoute\Route; // frontend
$defaultRoute->create();
$defaultRoute = new HosamAldeen\AutoRoute\Route; //backend
$defaultRoute->prefix = '/backend';
$defaultRoute->middleware = ['web'];
$defaultRoute->namespace = 'Backend';
$defaultRoute->create();