Passed
Pull Request — master (#1)
by Tom
02:13
created

RestfulResourceRegistrar::addResourceShowExtra()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 4
1
<?php
2
3
namespace TomHart\Restful\Routing;
4
5
use Illuminate\Routing\ResourceRegistrar;
6
use Illuminate\Routing\Route;
7
use Illuminate\Routing\Router;
8
9
class RestfulResourceRegistrar extends ResourceRegistrar
10
{
11
12
13
    public function __construct(Router $router)
14
    {
15
        parent::__construct($router);
16
17
        $this->resourceDefaults[] = 'showExtra';
18
    }
19
20
    /**
21
     * Add the show-extra method for a resourceful route.
22
     *
23
     * @param string $name
24
     * @param string $base
25
     * @param string $controller
26
     * @param mixed[] $options
27
     * @return Route
28
     */
29
    protected function addResourceShowExtra($name, $base, $controller, $options)
30
    {
31
        $uri = $this->getResourceUri($name) . '/{' . $base . '}/{extra}';
32
33
        $action = $this->getResourceAction($name, $controller, 'show', $options);
34
35
        $action['as'] .= '.extra';
36
37
        return $this->router->get($uri, $action)->where('extra', '.*');
38
    }
39
}
40