Issues (1)

src/RouteModuleMacroServiceProvider.php (1 issue)

1
<?php
2
3
namespace TheJawker\RouteModuleMacro;
4
5
use Illuminate\Support\Str;
6
use Illuminate\Routing\Router;
7
use Illuminate\Support\ServiceProvider;
8
9
class RouteModuleMacroServiceProvider extends ServiceProvider
10
{
11
    public function register()
12
    {
13
        if (!Router::hasMacro('module')) {
14
            $this->registerMacro();
15
        }
16
    }
17
18
    private function registerMacro()
19
    {
20
        Router::macro('module', function ($module, $only = [], $options = []) {
21
            $onlyOptions = count($only) ? ['only' => $only] : [];
22
23
            $controllerNameArray = collect(explode('.', $module))->map(function ($name) {
24
                return Str::studly($name);
25
            });
26
27
            $lastName = $controllerNameArray->pop();
28
29
            $controllerName = $controllerNameArray->map(function ($name) {
30
                return Str::singular($name);
31
            })->push($lastName)->push('Controller')->implode('');
32
33
            Router::resource($module, $controllerName, array_merge($onlyOptions, $options));
0 ignored issues
show
Bug Best Practice introduced by
The method Illuminate\Routing\Router::resource() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

33
            Router::/** @scrutinizer ignore-call */ 
34
                    resource($module, $controllerName, array_merge($onlyOptions, $options));
Loading history...
34
        });
35
    }
36
}
37