Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--added the option to filter routes by config value #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<?php
return [
'filter' => '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)
7 changes: 6 additions & 1 deletion src/Lord/Laroute/Routes/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Lord\Laroute\Routes;

use Config;
use Illuminate\Routing\Route;
use Illuminate\Routing\RouteCollection;
use Lord\Laroute\Routes\Exceptions\ZeroRoutesException;
Expand Down Expand Up @@ -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;
}

Expand Down
7 changes: 7 additions & 0 deletions src/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down