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

Add the option to disable the action in the laroute call #73

Closed
wants to merge 1 commit into from
Closed
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
8 changes: 7 additions & 1 deletion config/laroute.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,19 @@
*/
'action_namespace' => '',

/*
* If we use the actions, this will expose the PHP classes and methods
* See: https://github.com/aaronlord/laroute/issues/58
*/
'use_actions' => true,

/*
* 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
* with them.
*/
'template' => 'vendor/lord/laroute/src/templates/laroute.js',

/*
* Appends a prefix to URLs. By default the prefix is an empty string.
*
Expand Down
2 changes: 1 addition & 1 deletion src/LarouteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ protected function registerCommand()
'command.laroute.generate',
function ($app) {
$config = $app['config'];
$routes = new Routes($app['router']->getRoutes(), $config->get('laroute.filter', 'all'), $config->get('laroute.action_namespace', ''));
$routes = new Routes($app['router']->getRoutes(), $config->get('laroute.filter', 'all'), $config->get('laroute.action_namespace', ''), $config->get('laroute.use_actions', true));
$generator = $app->make('Lord\Laroute\Generators\GeneratorInterface');

return new LarouteGeneratorCommand($config, $routes, $generator);
Expand Down
23 changes: 13 additions & 10 deletions src/Routes/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

class Collection extends \Illuminate\Support\Collection
{
public function __construct(RouteCollection $routes, $filter, $namespace)
public function __construct(RouteCollection $routes, $filter, $namespace, $useActions = true)
{
$this->items = $this->parseRoutes($routes, $filter, $namespace);
$this->items = $this->parseRoutes($routes, $filter, $namespace, $useActions);
}

/**
Expand All @@ -23,14 +23,14 @@ public function __construct(RouteCollection $routes, $filter, $namespace)
* @return array
* @throws ZeroRoutesException
*/
protected function parseRoutes(RouteCollection $routes, $filter, $namespace)
protected function parseRoutes(RouteCollection $routes, $filter, $namespace, $useActions)
{
$this->guardAgainstZeroRoutes($routes);

$results = [];

foreach ($routes as $route) {
$results[] = $this->getRouteInformation($route, $filter, $namespace);
$results[] = $this->getRouteInformation($route, $filter, $namespace, $useActions);
}

return array_values(array_filter($results));
Expand Down Expand Up @@ -59,20 +59,23 @@ protected function guardAgainstZeroRoutes(RouteCollection $routes)
*
* @return array
*/
protected function getRouteInformation(Route $route, $filter, $namespace)
protected function getRouteInformation(Route $route, $filter, $namespace, $useActions)
{
$host = $route->domain();
$methods = $route->methods();
$uri = $route->uri();
$name = $route->getName();
$action = $route->getActionName();
$action = '';
$laroute = array_get($route->getAction(), 'laroute', null);

if(!empty($namespace)) {
$a = $route->getAction();
if ($useActions) {
$action = $route->getActionName();
if(!empty($namespace)) {
$a = $route->getAction();

if(isset($a['controller'])) {
$action = str_replace($namespace.'\\', '', $action);
if(isset($a['controller'])) {
$action = str_replace($namespace.'\\', '', $action);
}
}
}

Expand Down