diff --git a/readme.md b/readme.md index 1837427..0b88e0b 100644 --- a/readme.md +++ b/readme.md @@ -194,7 +194,33 @@ Route::group(['laroute' => false], function () { ``` +Another way to filter your routes is to set the ```filter``` option in config file so only the routes with specific key will be added to the laroute. Same key can be applied to group to add every route in it. +###### app/config/packages/lord/laroute/config.php +```php + 'jsroutes' +]; +``` +###### app/routes.php +```php +Route::get('/i-will-be-added', [ + 'jsroutes' => true, + 'as' => 'route', + 'uses' => 'Controller@me' +]); +Route::get('/i-wont-be-added', [ + 'as' => 'route', + 'uses' => 'Controller@me' +]); +Route::get('/i-wont-be-added-too', [ + 'jsroutes' => true, + 'laroute' => false, + 'as' => 'route', + 'uses' => 'Controller@me' +]); +``` ## Licence [View the licence in this repo.](https://github.com/aaronlord/laroute/blob/master/LICENSE) diff --git a/src/Lord/Laroute/Routes/Collection.php b/src/Lord/Laroute/Routes/Collection.php index e568cbf..964c46b 100644 --- a/src/Lord/Laroute/Routes/Collection.php +++ b/src/Lord/Laroute/Routes/Collection.php @@ -2,6 +2,7 @@ namespace Lord\Laroute\Routes; +use Config; use Illuminate\Routing\Route; use Illuminate\Routing\RouteCollection; use Lord\Laroute\Routes\Exceptions\ZeroRoutesException; @@ -60,7 +61,11 @@ protected function getRouteInformation(Route $route) $action = $route->getActionName(); $laroute = array_get($route->getAction(), 'laroute', true); - if ($laroute === false) { + $filter = Config::get('laroute::config.filter'); + + $routeHasFilter = array_get($route->getAction(), $filter, false); + + if (($filter and !$routeHasFilter) or $laroute === false) { return null; } diff --git a/src/config/config.php b/src/config/config.php index 7da5052..c40f739 100644 --- a/src/config/config.php +++ b/src/config/config.php @@ -18,6 +18,13 @@ */ 'namespace' => 'laroute', + /** + * This allows to specify a filter for generated routes, if one is specified and you + * add the filter to the route or group of routes only this routes will be added to file, + * still, if route has laroute => false it will not be added + */ + 'filter' => null, + /** * The path to the template `laroute.js` file. This is the file that contains * the ported helper Laravel url/route functions and the route data to go