|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace neilherbertuk\modules\Traits; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\App; |
|
6
|
|
|
|
|
7
|
|
|
trait MakeModule |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* @param $module |
|
11
|
|
|
*/ |
|
12
|
|
|
protected function createModule($module) |
|
13
|
|
|
{ |
|
14
|
|
|
$this->info("Creating a new Module"); |
|
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
if (is_dir(base_path('app/Modules/' . $module))) { |
|
17
|
|
|
$this->error("$module already exists. If you really want to create this module, please delete the following folder: " . base_path('app/Modules/' . $module)); |
|
|
|
|
|
|
18
|
|
|
return; |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
// Create all module's folders |
|
22
|
|
|
$this->info("Creating folder structure"); |
|
23
|
|
|
$this->createModuleFolders($module); |
|
24
|
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
// Create routes file |
|
27
|
|
|
|
|
28
|
|
|
// API Routes File |
|
29
|
|
|
if ($this->option('apiroute')) { |
|
|
|
|
|
|
30
|
|
|
$this->createApiRoutesFile($module); |
|
|
|
|
|
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
// Web Routes File |
|
34
|
|
|
if ($this->option('webroute') || !$this->option('apiroute')) { |
|
35
|
|
|
$this->createWebRoutesFile($module); |
|
|
|
|
|
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
$this->info('Done'); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @param $module |
|
43
|
|
|
*/ |
|
44
|
|
|
protected function createModuleFolders($module) |
|
45
|
|
|
{ |
|
46
|
|
|
$this->createViewsFolder($module); |
|
47
|
|
|
$this->createControllersFolder($module); |
|
|
|
|
|
|
48
|
|
|
$this->createDatabaseMigrationsFolder($module); |
|
49
|
|
|
$this->createModelsFolder($module); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param $module |
|
54
|
|
|
*/ |
|
55
|
|
|
protected function createModelsFolder($module) |
|
56
|
|
|
{ |
|
57
|
|
|
$this->createFolderInModule($module, "Models"); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @param $module |
|
62
|
|
|
*/ |
|
63
|
|
|
protected function createDatabaseMigrationsFolder($module) |
|
64
|
|
|
{ |
|
65
|
|
|
$this->createFolderInModule($module, "Database/Migrations"); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @param $module |
|
70
|
|
|
*/ |
|
71
|
|
|
protected function createViewsFolder($module) |
|
72
|
|
|
{ |
|
73
|
|
|
$this->createFolderInModule($module, "Views"); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @param $module |
|
78
|
|
|
* @param $folder |
|
79
|
|
|
* @return bool |
|
80
|
|
|
*/ |
|
81
|
|
|
protected function createFolderInModule($module, $folder) |
|
82
|
|
|
{ |
|
83
|
|
|
// Does Directory Exist? |
|
84
|
|
|
if (!is_dir(base_path() . "/app/Modules/" . $module . "/" . $folder)) { |
|
85
|
|
|
// Create directory |
|
86
|
|
|
return mkdir(base_path() . "/app/Modules/" . $module . "/" . $folder, 0755, true); |
|
87
|
|
|
} |
|
88
|
|
|
return false; |
|
89
|
|
|
} |
|
90
|
|
|
} |