Skip to content

Commit

Permalink
Fixing the issue #5
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanedev-maroc committed Sep 23, 2015
1 parent 82b9bd3 commit f280021
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/Routing/ResourceRegistrar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php namespace Arcanedev\Localization\Routing;

use Illuminate\Routing\ResourceRegistrar as IlluminateResourceRegistrar;

/**
* Class ResourceRegistrar
*
* @package Arcanedev\Localization\Routing
* @author ARCANEDEV <[email protected]>
*/
class ResourceRegistrar extends IlluminateResourceRegistrar
{
/* ------------------------------------------------------------------------------------------------
| Main Functions
| ------------------------------------------------------------------------------------------------
*/
/**
* Get the resource name for a grouped resource.
*
* @param string $prefix
* @param string $resource
* @param string $method
* @return string
*/
protected function getGroupResourceName($prefix, $resource, $method)
{
$group = trim(str_replace('/', '.', $this->router->getLastGroupPrefix()), '.');

if ( ! empty($group) && $group !== localization()->getCurrentLocale()) {
return trim("{$prefix}{$group}.{$resource}.{$method}", '.');
}

return trim("{$prefix}{$resource}.{$method}", '.');
}
}
19 changes: 19 additions & 0 deletions src/Routing/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,25 @@ protected function getActiveMiddlewares()
return array_keys(array_filter($middleware));
}

/* ------------------------------------------------------------------------------------------------
| Basic Route Functions
| ------------------------------------------------------------------------------------------------
*/
/**
* Route a resource to a controller.
*
* @param string $name
* @param string $controller
* @param array $options
* @return void
*/
public function resource($name, $controller, array $options = [])
{
$registrar = new ResourceRegistrar($this);

$registrar->register($name, $controller, $options);
}

/* ------------------------------------------------------------------------------------------------
| Route Functions
| ------------------------------------------------------------------------------------------------
Expand Down
14 changes: 14 additions & 0 deletions tests/Stubs/Http/Controllers/BarController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php namespace Arcanedev\Localization\Tests\Stubs\Http\Controllers;

use Illuminate\Routing\Controller;

/**
* Class BarController
*
* @package Arcanedev\Localization\Tests\Stubs\Http\Controllers
* @author ARCANEDEV <[email protected]>
*/
class BarController extends Controller
{
//
}
14 changes: 14 additions & 0 deletions tests/Stubs/Http/Controllers/DummyController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php namespace Arcanedev\Localization\Tests\Stubs\Http\Controllers;

use Illuminate\Routing\Controller;

/**
* Class DummyController
*
* @package Arcanedev\Localization\Tests\Stubs\Http\Controllers
* @author ARCANEDEV <[email protected]>
*/
class DummyController extends Controller
{
//
}
10 changes: 10 additions & 0 deletions tests/Stubs/Http/RouteRegistrar.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,16 @@ function () {
return 'Any method';
}
]);

/* ------------------------------------------------------------------------------------------------
| Resource Controller
| ------------------------------------------------------------------------------------------------
*/
$this->router->resource('dummy', Controllers\DummyController::class);

$this->router->group(['prefix' => 'foo'], function () {
$this->router->resource('Bar', Controllers\BarController::class);
});
});
}
}

0 comments on commit f280021

Please sign in to comment.