1 | <?php |
||
2 | |||
3 | namespace neilherbertuk\modules\Traits; |
||
4 | |||
5 | use Illuminate\Support\Facades\App; |
||
6 | |||
7 | trait MakeRoutes{ |
||
8 | /** |
||
9 | * @param $module |
||
10 | */ |
||
11 | protected function createWebRoutesFile($module) |
||
12 | { |
||
13 | $this->createRoutesFile($module, "web"); |
||
14 | } |
||
15 | |||
16 | /** |
||
17 | * @param $module |
||
18 | */ |
||
19 | protected function createApiRoutesFile($module) |
||
20 | { |
||
21 | $this->createRoutesFile($module, "api"); |
||
22 | } |
||
23 | |||
24 | /** |
||
25 | * @param $module |
||
26 | */ |
||
27 | protected function createRoutesFile($module, $type) |
||
28 | { |
||
29 | if (!file_exists(base_path() . "/app/Modules/" . $module . "/" . $type . ".php")) { |
||
30 | $this->info("Creating $type routes file"); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
31 | file_put_contents( |
||
32 | base_path() . "/app/Modules/" . $module . "/" . $type . ".php", |
||
33 | $this->compileRoutesStub($module, $type) |
||
34 | ); |
||
35 | } |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * @param $module |
||
40 | * @param $type |
||
41 | * @return mixed |
||
42 | */ |
||
43 | protected function compileRoutesStub($module, $type) |
||
44 | { |
||
45 | return str_replace( |
||
46 | ['{{moduleName}}', '{{routeType}}'], |
||
47 | [$module, $type], |
||
48 | file_get_contents(__DIR__ . '/../Stubs/route.stub') |
||
49 | ); |
||
50 | } |
||
51 | } |
||
52 |