@@ -6,15 +6,15 @@ |
||
6 | 6 | |
7 | 7 | class ClearDataSeeder extends Seeder |
8 | 8 | { |
9 | - /** |
|
10 | - * Run the database seeds. |
|
11 | - * |
|
12 | - * @return void |
|
13 | - */ |
|
14 | - public function run() |
|
15 | - { |
|
16 | - $permissions = \DB::table('permissions')->whereIn('model', ['role']); |
|
17 | - \DB::table('permission_role')->whereIn('permission_id', $permissions->pluck('id'))->delete(); |
|
18 | - $permissions->delete(); |
|
19 | - } |
|
9 | + /** |
|
10 | + * Run the database seeds. |
|
11 | + * |
|
12 | + * @return void |
|
13 | + */ |
|
14 | + public function run() |
|
15 | + { |
|
16 | + $permissions = \DB::table('permissions')->whereIn('model', ['role']); |
|
17 | + \DB::table('permission_role')->whereIn('permission_id', $permissions->pluck('id'))->delete(); |
|
18 | + $permissions->delete(); |
|
19 | + } |
|
20 | 20 | } |
@@ -5,40 +5,40 @@ |
||
5 | 5 | |
6 | 6 | class Roles extends Migration |
7 | 7 | { |
8 | - /** |
|
9 | - * Run the migrations. |
|
10 | - * |
|
11 | - * @return void |
|
12 | - */ |
|
13 | - public function up() |
|
14 | - { |
|
15 | - Schema::create('roles', function (Blueprint $table) { |
|
16 | - $table->increments('id'); |
|
17 | - $table->string('name', 100)->unique(); |
|
18 | - $table->softDeletes(); |
|
19 | - $table->timestamps(); |
|
20 | - }); |
|
8 | + /** |
|
9 | + * Run the migrations. |
|
10 | + * |
|
11 | + * @return void |
|
12 | + */ |
|
13 | + public function up() |
|
14 | + { |
|
15 | + Schema::create('roles', function (Blueprint $table) { |
|
16 | + $table->increments('id'); |
|
17 | + $table->string('name', 100)->unique(); |
|
18 | + $table->softDeletes(); |
|
19 | + $table->timestamps(); |
|
20 | + }); |
|
21 | 21 | |
22 | - Schema::create('role_user', function (Blueprint $table) { |
|
23 | - $table->increments('id'); |
|
24 | - $table->unsignedInteger('user_id'); |
|
25 | - $table->unsignedInteger('role_id'); |
|
26 | - $table->softDeletes(); |
|
27 | - $table->timestamps(); |
|
22 | + Schema::create('role_user', function (Blueprint $table) { |
|
23 | + $table->increments('id'); |
|
24 | + $table->unsignedInteger('user_id'); |
|
25 | + $table->unsignedInteger('role_id'); |
|
26 | + $table->softDeletes(); |
|
27 | + $table->timestamps(); |
|
28 | 28 | |
29 | - $table->foreign('user_id')->references('id')->on('users'); |
|
30 | - $table->foreign('role_id')->references('id')->on('roles'); |
|
31 | - }); |
|
32 | - } |
|
29 | + $table->foreign('user_id')->references('id')->on('users'); |
|
30 | + $table->foreign('role_id')->references('id')->on('roles'); |
|
31 | + }); |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * Reverse the migrations. |
|
36 | - * |
|
37 | - * @return void |
|
38 | - */ |
|
39 | - public function down() |
|
40 | - { |
|
41 | - Schema::dropIfExists('roles'); |
|
42 | - Schema::dropIfExists('role_user'); |
|
43 | - } |
|
34 | + /** |
|
35 | + * Reverse the migrations. |
|
36 | + * |
|
37 | + * @return void |
|
38 | + */ |
|
39 | + public function down() |
|
40 | + { |
|
41 | + Schema::dropIfExists('roles'); |
|
42 | + Schema::dropIfExists('role_user'); |
|
43 | + } |
|
44 | 44 | } |
@@ -12,14 +12,14 @@ |
||
12 | 12 | */ |
13 | 13 | public function up() |
14 | 14 | { |
15 | - Schema::create('roles', function (Blueprint $table) { |
|
15 | + Schema::create('roles', function(Blueprint $table) { |
|
16 | 16 | $table->increments('id'); |
17 | 17 | $table->string('name', 100)->unique(); |
18 | 18 | $table->softDeletes(); |
19 | 19 | $table->timestamps(); |
20 | 20 | }); |
21 | 21 | |
22 | - Schema::create('role_user', function (Blueprint $table) { |
|
22 | + Schema::create('role_user', function(Blueprint $table) { |
|
23 | 23 | $table->increments('id'); |
24 | 24 | $table->unsignedInteger('user_id'); |
25 | 25 | $table->unsignedInteger('role_id'); |
@@ -10,54 +10,54 @@ |
||
10 | 10 | |
11 | 11 | class RoleController extends BaseApiController |
12 | 12 | { |
13 | - /** |
|
14 | - * Path of the model resource |
|
15 | - * |
|
16 | - * @var string |
|
17 | - */ |
|
18 | - protected $modelResource = 'App\Modules\Roles\Http\Resources\Role'; |
|
13 | + /** |
|
14 | + * Path of the model resource |
|
15 | + * |
|
16 | + * @var string |
|
17 | + */ |
|
18 | + protected $modelResource = 'App\Modules\Roles\Http\Resources\Role'; |
|
19 | 19 | |
20 | - /** |
|
21 | - * Init new object. |
|
22 | - * |
|
23 | - * @param RoleService $service |
|
24 | - * @return void |
|
25 | - */ |
|
26 | - public function __construct(RoleService $service) |
|
27 | - { |
|
28 | - parent::__construct($service); |
|
29 | - } |
|
20 | + /** |
|
21 | + * Init new object. |
|
22 | + * |
|
23 | + * @param RoleService $service |
|
24 | + * @return void |
|
25 | + */ |
|
26 | + public function __construct(RoleService $service) |
|
27 | + { |
|
28 | + parent::__construct($service); |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * Insert the given model to storage. |
|
33 | - * |
|
34 | - * @param InsertRole $request |
|
35 | - * @return \Illuminate\Http\Response |
|
36 | - */ |
|
37 | - public function insert(InsertRole $request) |
|
38 | - { |
|
39 | - return new $this->modelResource($this->service->save($request->all())); |
|
40 | - } |
|
31 | + /** |
|
32 | + * Insert the given model to storage. |
|
33 | + * |
|
34 | + * @param InsertRole $request |
|
35 | + * @return \Illuminate\Http\Response |
|
36 | + */ |
|
37 | + public function insert(InsertRole $request) |
|
38 | + { |
|
39 | + return new $this->modelResource($this->service->save($request->all())); |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * Update the given model to storage. |
|
44 | - * |
|
45 | - * @param UpdateRole $request |
|
46 | - * @return \Illuminate\Http\Response |
|
47 | - */ |
|
48 | - public function update(UpdateRole $request) |
|
49 | - { |
|
50 | - return new $this->modelResource($this->service->save($request->all())); |
|
51 | - } |
|
42 | + /** |
|
43 | + * Update the given model to storage. |
|
44 | + * |
|
45 | + * @param UpdateRole $request |
|
46 | + * @return \Illuminate\Http\Response |
|
47 | + */ |
|
48 | + public function update(UpdateRole $request) |
|
49 | + { |
|
50 | + return new $this->modelResource($this->service->save($request->all())); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Handle an assign permissions to role request. |
|
55 | - * |
|
56 | - * @param AssignPermissions $request |
|
57 | - * @return \Illuminate\Http\Response |
|
58 | - */ |
|
59 | - public function assignPermissions(AssignPermissions $request) |
|
60 | - { |
|
61 | - return new $this->modelResource($this->service->assignPermissions($request->get('role_id'), $request->get('permission_ids'))); |
|
62 | - } |
|
53 | + /** |
|
54 | + * Handle an assign permissions to role request. |
|
55 | + * |
|
56 | + * @param AssignPermissions $request |
|
57 | + * @return \Illuminate\Http\Response |
|
58 | + */ |
|
59 | + public function assignPermissions(AssignPermissions $request) |
|
60 | + { |
|
61 | + return new $this->modelResource($this->service->assignPermissions($request->get('role_id'), $request->get('permission_ids'))); |
|
62 | + } |
|
63 | 63 | } |
@@ -5,14 +5,14 @@ |
||
5 | 5 | |
6 | 6 | class SettingRepository extends BaseRepository |
7 | 7 | { |
8 | - /** |
|
9 | - * Init new object. |
|
10 | - * |
|
11 | - * @param Setting $model |
|
12 | - * @return void |
|
13 | - */ |
|
14 | - public function __construct(Setting $model) |
|
15 | - { |
|
16 | - parent::__construct($model); |
|
17 | - } |
|
8 | + /** |
|
9 | + * Init new object. |
|
10 | + * |
|
11 | + * @param Setting $model |
|
12 | + * @return void |
|
13 | + */ |
|
14 | + public function __construct(Setting $model) |
|
15 | + { |
|
16 | + parent::__construct($model); |
|
17 | + } |
|
18 | 18 | } |
@@ -6,27 +6,27 @@ |
||
6 | 6 | |
7 | 7 | class AssignRelationsSeeder extends Seeder |
8 | 8 | { |
9 | - /** |
|
10 | - * Run the database seeds. |
|
11 | - * |
|
12 | - * @return void |
|
13 | - */ |
|
14 | - public function run() |
|
15 | - { |
|
16 | - $adminRoleId = \DB::table('roles')->where('name', 'admin')->select('id')->first()->id; |
|
9 | + /** |
|
10 | + * Run the database seeds. |
|
11 | + * |
|
12 | + * @return void |
|
13 | + */ |
|
14 | + public function run() |
|
15 | + { |
|
16 | + $adminRoleId = \DB::table('roles')->where('name', 'admin')->select('id')->first()->id; |
|
17 | 17 | |
18 | - /** |
|
19 | - * Assign the permissions to the admin role. |
|
20 | - */ |
|
21 | - \DB::table('permissions')->orderBy('created_at', 'asc')->whereIn('model', ['DummyModelName'])->each(function ($permission) use ($adminRoleId) { |
|
22 | - \DB::table('permission_role')->insert( |
|
23 | - [ |
|
24 | - 'permission_id' => $permission->id, |
|
25 | - 'role_id' => $adminRoleId, |
|
26 | - 'created_at' => \DB::raw('NOW()'), |
|
27 | - 'updated_at' => \DB::raw('NOW()') |
|
28 | - ] |
|
29 | - ); |
|
30 | - }); |
|
31 | - } |
|
18 | + /** |
|
19 | + * Assign the permissions to the admin role. |
|
20 | + */ |
|
21 | + \DB::table('permissions')->orderBy('created_at', 'asc')->whereIn('model', ['DummyModelName'])->each(function ($permission) use ($adminRoleId) { |
|
22 | + \DB::table('permission_role')->insert( |
|
23 | + [ |
|
24 | + 'permission_id' => $permission->id, |
|
25 | + 'role_id' => $adminRoleId, |
|
26 | + 'created_at' => \DB::raw('NOW()'), |
|
27 | + 'updated_at' => \DB::raw('NOW()') |
|
28 | + ] |
|
29 | + ); |
|
30 | + }); |
|
31 | + } |
|
32 | 32 | } |
@@ -18,7 +18,7 @@ |
||
18 | 18 | /** |
19 | 19 | * Assign the permissions to the admin role. |
20 | 20 | */ |
21 | - \DB::table('permissions')->orderBy('created_at', 'asc')->whereIn('model', ['DummyModelName'])->each(function ($permission) use ($adminRoleId) { |
|
21 | + \DB::table('permissions')->orderBy('created_at', 'asc')->whereIn('model', ['DummyModelName'])->each(function($permission) use ($adminRoleId) { |
|
22 | 22 | \DB::table('permission_role')->insert( |
23 | 23 | [ |
24 | 24 | 'permission_id' => $permission->id, |
@@ -6,15 +6,15 @@ |
||
6 | 6 | |
7 | 7 | class ClearDataSeeder extends Seeder |
8 | 8 | { |
9 | - /** |
|
10 | - * Run the database seeds. |
|
11 | - * |
|
12 | - * @return void |
|
13 | - */ |
|
14 | - public function run() |
|
15 | - { |
|
16 | - $permissions = \DB::table('permissions')->whereIn('model', ['DummyModelName']); |
|
17 | - \DB::table('permission_role')->whereIn('permission_id', $permissions->pluck('id'))->delete(); |
|
18 | - $permissions->delete(); |
|
19 | - } |
|
9 | + /** |
|
10 | + * Run the database seeds. |
|
11 | + * |
|
12 | + * @return void |
|
13 | + */ |
|
14 | + public function run() |
|
15 | + { |
|
16 | + $permissions = \DB::table('permissions')->whereIn('model', ['DummyModelName']); |
|
17 | + \DB::table('permission_role')->whereIn('permission_id', $permissions->pluck('id'))->delete(); |
|
18 | + $permissions->delete(); |
|
19 | + } |
|
20 | 20 | } |
@@ -8,271 +8,271 @@ |
||
8 | 8 | |
9 | 9 | class GenerateDoc extends Command |
10 | 10 | { |
11 | - /** |
|
12 | - * The name and signature of the console command. |
|
13 | - * |
|
14 | - * @var string |
|
15 | - */ |
|
16 | - protected $signature = 'doc:generate'; |
|
11 | + /** |
|
12 | + * The name and signature of the console command. |
|
13 | + * |
|
14 | + * @var string |
|
15 | + */ |
|
16 | + protected $signature = 'doc:generate'; |
|
17 | 17 | |
18 | - /** |
|
19 | - * The console command description. |
|
20 | - * |
|
21 | - * @var string |
|
22 | - */ |
|
23 | - protected $description = 'Generate api documentation'; |
|
18 | + /** |
|
19 | + * The console command description. |
|
20 | + * |
|
21 | + * @var string |
|
22 | + */ |
|
23 | + protected $description = 'Generate api documentation'; |
|
24 | 24 | |
25 | - /** |
|
26 | - * @var ReprotService |
|
27 | - */ |
|
28 | - protected $reportService; |
|
25 | + /** |
|
26 | + * @var ReprotService |
|
27 | + */ |
|
28 | + protected $reportService; |
|
29 | 29 | |
30 | - /** |
|
31 | - * Init new object. |
|
32 | - * |
|
33 | - * @return void |
|
34 | - */ |
|
35 | - public function __construct(ReportService $reportService) |
|
36 | - { |
|
37 | - $this->reportService = $reportService; |
|
38 | - parent::__construct(); |
|
39 | - } |
|
30 | + /** |
|
31 | + * Init new object. |
|
32 | + * |
|
33 | + * @return void |
|
34 | + */ |
|
35 | + public function __construct(ReportService $reportService) |
|
36 | + { |
|
37 | + $this->reportService = $reportService; |
|
38 | + parent::__construct(); |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * Execute the console command. |
|
43 | - * |
|
44 | - * @return mixed |
|
45 | - */ |
|
46 | - public function handle() |
|
47 | - { |
|
48 | - $docData = []; |
|
49 | - $docData['models'] = []; |
|
50 | - $routes = $this->getRoutes(); |
|
51 | - foreach ($routes as $route) { |
|
52 | - if ($route) { |
|
53 | - $actoinArray = explode('@', $route['action']); |
|
54 | - if (Arr::get($actoinArray, 1, false)) { |
|
55 | - $controller = $actoinArray[0]; |
|
56 | - $method = $actoinArray[1]; |
|
57 | - $route['name'] = $method !== 'index' ? $method : 'list'; |
|
41 | + /** |
|
42 | + * Execute the console command. |
|
43 | + * |
|
44 | + * @return mixed |
|
45 | + */ |
|
46 | + public function handle() |
|
47 | + { |
|
48 | + $docData = []; |
|
49 | + $docData['models'] = []; |
|
50 | + $routes = $this->getRoutes(); |
|
51 | + foreach ($routes as $route) { |
|
52 | + if ($route) { |
|
53 | + $actoinArray = explode('@', $route['action']); |
|
54 | + if (Arr::get($actoinArray, 1, false)) { |
|
55 | + $controller = $actoinArray[0]; |
|
56 | + $method = $actoinArray[1]; |
|
57 | + $route['name'] = $method !== 'index' ? $method : 'list'; |
|
58 | 58 | |
59 | - $reflectionClass = new \ReflectionClass($controller); |
|
60 | - $reflectionMethod = $reflectionClass->getMethod($method); |
|
61 | - $classProperties = $reflectionClass->getDefaultProperties(); |
|
62 | - $skipLoginCheck = Arr::get($classProperties, 'skipLoginCheck', false); |
|
63 | - $modelName = explode('\\', $controller); |
|
64 | - $modelName = lcfirst(str_replace('Controller', '', end($modelName))); |
|
59 | + $reflectionClass = new \ReflectionClass($controller); |
|
60 | + $reflectionMethod = $reflectionClass->getMethod($method); |
|
61 | + $classProperties = $reflectionClass->getDefaultProperties(); |
|
62 | + $skipLoginCheck = Arr::get($classProperties, 'skipLoginCheck', false); |
|
63 | + $modelName = explode('\\', $controller); |
|
64 | + $modelName = lcfirst(str_replace('Controller', '', end($modelName))); |
|
65 | 65 | |
66 | - $this->processDocBlock($route, $reflectionMethod); |
|
67 | - $this->getHeaders($route, $method, $skipLoginCheck); |
|
68 | - $this->getPostData($route, $reflectionMethod); |
|
66 | + $this->processDocBlock($route, $reflectionMethod); |
|
67 | + $this->getHeaders($route, $method, $skipLoginCheck); |
|
68 | + $this->getPostData($route, $reflectionMethod); |
|
69 | 69 | |
70 | - $route['response'] = $this->getResponseObject($modelName, $route['name'], $route['returnDocBlock']); |
|
70 | + $route['response'] = $this->getResponseObject($modelName, $route['name'], $route['returnDocBlock']); |
|
71 | 71 | |
72 | - $module = $route['prefix']; |
|
73 | - $module = \Str::camel(str_replace('/', '_', str_replace('api', '', $module))); |
|
74 | - $docData['modules'][$module][] = $route; |
|
72 | + $module = $route['prefix']; |
|
73 | + $module = \Str::camel(str_replace('/', '_', str_replace('api', '', $module))); |
|
74 | + $docData['modules'][$module][] = $route; |
|
75 | 75 | |
76 | - $this->getModels($modelName, $docData, $reflectionClass); |
|
77 | - } |
|
78 | - } |
|
79 | - } |
|
76 | + $this->getModels($modelName, $docData, $reflectionClass); |
|
77 | + } |
|
78 | + } |
|
79 | + } |
|
80 | 80 | |
81 | - $docData['errors'] = $this->getErrors(); |
|
82 | - $docData['reports'] = $this->reportService->all(); |
|
83 | - \File::put(app_path('Modules/Core/Resources/api.json'), json_encode($docData)); |
|
84 | - } |
|
81 | + $docData['errors'] = $this->getErrors(); |
|
82 | + $docData['reports'] = $this->reportService->all(); |
|
83 | + \File::put(app_path('Modules/Core/Resources/api.json'), json_encode($docData)); |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * Get list of all registered routes. |
|
88 | - * |
|
89 | - * @return collection |
|
90 | - */ |
|
91 | - protected function getRoutes() |
|
92 | - { |
|
93 | - return collect(\Route::getRoutes())->map(function ($route) { |
|
94 | - if (strpos($route->uri(), 'api/') !== false) { |
|
95 | - return [ |
|
96 | - 'method' => $route->methods()[0], |
|
97 | - 'uri' => $route->uri(), |
|
98 | - 'action' => $route->getActionName(), |
|
99 | - 'prefix' => $route->getPrefix() |
|
100 | - ]; |
|
101 | - } |
|
102 | - return false; |
|
103 | - })->all(); |
|
104 | - } |
|
86 | + /** |
|
87 | + * Get list of all registered routes. |
|
88 | + * |
|
89 | + * @return collection |
|
90 | + */ |
|
91 | + protected function getRoutes() |
|
92 | + { |
|
93 | + return collect(\Route::getRoutes())->map(function ($route) { |
|
94 | + if (strpos($route->uri(), 'api/') !== false) { |
|
95 | + return [ |
|
96 | + 'method' => $route->methods()[0], |
|
97 | + 'uri' => $route->uri(), |
|
98 | + 'action' => $route->getActionName(), |
|
99 | + 'prefix' => $route->getPrefix() |
|
100 | + ]; |
|
101 | + } |
|
102 | + return false; |
|
103 | + })->all(); |
|
104 | + } |
|
105 | 105 | |
106 | - /** |
|
107 | - * Generate headers for the given route. |
|
108 | - * |
|
109 | - * @param array &$route |
|
110 | - * @param string $method |
|
111 | - * @param array $skipLoginCheck |
|
112 | - * @return void |
|
113 | - */ |
|
114 | - protected function getHeaders(&$route, $method, $skipLoginCheck) |
|
115 | - { |
|
116 | - $route['headers'] = [ |
|
117 | - 'Accept' => 'application/json', |
|
118 | - 'Content-Type' => 'application/json', |
|
119 | - 'locale' => 'The language of the returned data: ar, en or all.', |
|
120 | - 'time-zone' => 'Your locale time zone', |
|
121 | - ]; |
|
106 | + /** |
|
107 | + * Generate headers for the given route. |
|
108 | + * |
|
109 | + * @param array &$route |
|
110 | + * @param string $method |
|
111 | + * @param array $skipLoginCheck |
|
112 | + * @return void |
|
113 | + */ |
|
114 | + protected function getHeaders(&$route, $method, $skipLoginCheck) |
|
115 | + { |
|
116 | + $route['headers'] = [ |
|
117 | + 'Accept' => 'application/json', |
|
118 | + 'Content-Type' => 'application/json', |
|
119 | + 'locale' => 'The language of the returned data: ar, en or all.', |
|
120 | + 'time-zone' => 'Your locale time zone', |
|
121 | + ]; |
|
122 | 122 | |
123 | 123 | |
124 | - if (! $skipLoginCheck || ! in_array($method, $skipLoginCheck)) { |
|
125 | - $route['headers']['Authorization'] = 'Bearer {token}'; |
|
126 | - } |
|
127 | - } |
|
124 | + if (! $skipLoginCheck || ! in_array($method, $skipLoginCheck)) { |
|
125 | + $route['headers']['Authorization'] = 'Bearer {token}'; |
|
126 | + } |
|
127 | + } |
|
128 | 128 | |
129 | - /** |
|
130 | - * Generate description and params for the given route |
|
131 | - * based on the docblock. |
|
132 | - * |
|
133 | - * @param array &$route |
|
134 | - * @param \ReflectionMethod $reflectionMethod |
|
135 | - * @return void |
|
136 | - */ |
|
137 | - protected function processDocBlock(&$route, $reflectionMethod) |
|
138 | - { |
|
139 | - $factory = \phpDocumentor\Reflection\DocBlockFactory::createInstance(); |
|
140 | - $docblock = $factory->create($reflectionMethod->getDocComment()); |
|
141 | - $route['description'] = trim(preg_replace('/\s+/', ' ', $docblock->getSummary())); |
|
142 | - $params = $docblock->getTagsByName('param'); |
|
143 | - $route['returnDocBlock'] = $docblock->getTagsByName('return')[0]->getType()->getFqsen()->getName(); |
|
129 | + /** |
|
130 | + * Generate description and params for the given route |
|
131 | + * based on the docblock. |
|
132 | + * |
|
133 | + * @param array &$route |
|
134 | + * @param \ReflectionMethod $reflectionMethod |
|
135 | + * @return void |
|
136 | + */ |
|
137 | + protected function processDocBlock(&$route, $reflectionMethod) |
|
138 | + { |
|
139 | + $factory = \phpDocumentor\Reflection\DocBlockFactory::createInstance(); |
|
140 | + $docblock = $factory->create($reflectionMethod->getDocComment()); |
|
141 | + $route['description'] = trim(preg_replace('/\s+/', ' ', $docblock->getSummary())); |
|
142 | + $params = $docblock->getTagsByName('param'); |
|
143 | + $route['returnDocBlock'] = $docblock->getTagsByName('return')[0]->getType()->getFqsen()->getName(); |
|
144 | 144 | |
145 | - foreach ($params as $param) { |
|
146 | - $name = $param->getVariableName(); |
|
147 | - if ($name !== 'request') { |
|
148 | - $route['parametars'][$param->getVariableName()] = $param->getDescription()->render(); |
|
149 | - } |
|
150 | - } |
|
145 | + foreach ($params as $param) { |
|
146 | + $name = $param->getVariableName(); |
|
147 | + if ($name !== 'request') { |
|
148 | + $route['parametars'][$param->getVariableName()] = $param->getDescription()->render(); |
|
149 | + } |
|
150 | + } |
|
151 | 151 | |
152 | - if ($route['name'] === 'list') { |
|
153 | - $route['parametars']['perPage'] = 'perPage'; |
|
154 | - $route['parametars']['sortBy'] = 'sortBy'; |
|
155 | - $route['parametars']['desc'] = 'desc'; |
|
156 | - } |
|
157 | - } |
|
152 | + if ($route['name'] === 'list') { |
|
153 | + $route['parametars']['perPage'] = 'perPage'; |
|
154 | + $route['parametars']['sortBy'] = 'sortBy'; |
|
155 | + $route['parametars']['desc'] = 'desc'; |
|
156 | + } |
|
157 | + } |
|
158 | 158 | |
159 | - /** |
|
160 | - * Generate post body for the given route. |
|
161 | - * |
|
162 | - * @param array &$route |
|
163 | - * @param \ReflectionMethod $reflectionMethod |
|
164 | - * @return void |
|
165 | - */ |
|
166 | - protected function getPostData(&$route, $reflectionMethod) |
|
167 | - { |
|
168 | - $parameters = $reflectionMethod->getParameters(); |
|
169 | - if (count($parameters)) { |
|
170 | - $className = optional($reflectionMethod->getParameters()[0]->getType())->getName(); |
|
171 | - if ($className) { |
|
172 | - $reflectionClass = new \ReflectionClass($className); |
|
159 | + /** |
|
160 | + * Generate post body for the given route. |
|
161 | + * |
|
162 | + * @param array &$route |
|
163 | + * @param \ReflectionMethod $reflectionMethod |
|
164 | + * @return void |
|
165 | + */ |
|
166 | + protected function getPostData(&$route, $reflectionMethod) |
|
167 | + { |
|
168 | + $parameters = $reflectionMethod->getParameters(); |
|
169 | + if (count($parameters)) { |
|
170 | + $className = optional($reflectionMethod->getParameters()[0]->getType())->getName(); |
|
171 | + if ($className) { |
|
172 | + $reflectionClass = new \ReflectionClass($className); |
|
173 | 173 | |
174 | - if ($reflectionClass->hasMethod('rules')) { |
|
175 | - $reflectionMethod = $reflectionClass->getMethod('rules'); |
|
176 | - $route['body'] = $reflectionMethod->invoke(new $className); |
|
174 | + if ($reflectionClass->hasMethod('rules')) { |
|
175 | + $reflectionMethod = $reflectionClass->getMethod('rules'); |
|
176 | + $route['body'] = $reflectionMethod->invoke(new $className); |
|
177 | 177 | |
178 | - foreach ($route['body'] as &$rule) { |
|
179 | - if (strpos($rule, 'unique')) { |
|
180 | - $rule = substr($rule, 0, strpos($rule, 'unique') + 6); |
|
181 | - } elseif (strpos($rule, 'exists')) { |
|
182 | - $rule = substr($rule, 0, strpos($rule, 'exists') - 1); |
|
183 | - } |
|
184 | - } |
|
185 | - } |
|
186 | - } |
|
187 | - } |
|
188 | - } |
|
178 | + foreach ($route['body'] as &$rule) { |
|
179 | + if (strpos($rule, 'unique')) { |
|
180 | + $rule = substr($rule, 0, strpos($rule, 'unique') + 6); |
|
181 | + } elseif (strpos($rule, 'exists')) { |
|
182 | + $rule = substr($rule, 0, strpos($rule, 'exists') - 1); |
|
183 | + } |
|
184 | + } |
|
185 | + } |
|
186 | + } |
|
187 | + } |
|
188 | + } |
|
189 | 189 | |
190 | - /** |
|
191 | - * Generate application errors. |
|
192 | - * |
|
193 | - * @return array |
|
194 | - */ |
|
195 | - protected function getErrors() |
|
196 | - { |
|
197 | - $errors = []; |
|
198 | - $reflectionClass = new \ReflectionClass('App\Modules\Core\Utl\ErrorHandler'); |
|
199 | - foreach ($reflectionClass->getMethods() as $method) { |
|
200 | - $methodName = $method->name; |
|
201 | - $reflectionMethod = $reflectionClass->getMethod($methodName); |
|
202 | - $body = $this->getMethodBody($reflectionMethod); |
|
190 | + /** |
|
191 | + * Generate application errors. |
|
192 | + * |
|
193 | + * @return array |
|
194 | + */ |
|
195 | + protected function getErrors() |
|
196 | + { |
|
197 | + $errors = []; |
|
198 | + $reflectionClass = new \ReflectionClass('App\Modules\Core\Utl\ErrorHandler'); |
|
199 | + foreach ($reflectionClass->getMethods() as $method) { |
|
200 | + $methodName = $method->name; |
|
201 | + $reflectionMethod = $reflectionClass->getMethod($methodName); |
|
202 | + $body = $this->getMethodBody($reflectionMethod); |
|
203 | 203 | |
204 | - preg_match('/\$error=\[\'status\'=>([^#]+)\,/iU', $body, $match); |
|
204 | + preg_match('/\$error=\[\'status\'=>([^#]+)\,/iU', $body, $match); |
|
205 | 205 | |
206 | - if (count($match)) { |
|
207 | - $errors[$match[1]][] = $methodName; |
|
208 | - } |
|
209 | - } |
|
206 | + if (count($match)) { |
|
207 | + $errors[$match[1]][] = $methodName; |
|
208 | + } |
|
209 | + } |
|
210 | 210 | |
211 | - return $errors; |
|
212 | - } |
|
211 | + return $errors; |
|
212 | + } |
|
213 | 213 | |
214 | - /** |
|
215 | - * Get the given method body code. |
|
216 | - * |
|
217 | - * @param object $reflectionMethod |
|
218 | - * @return string |
|
219 | - */ |
|
220 | - protected function getMethodBody($reflectionMethod) |
|
221 | - { |
|
222 | - $filename = $reflectionMethod->getFileName(); |
|
223 | - $start_line = $reflectionMethod->getStartLine() - 1; |
|
224 | - $end_line = $reflectionMethod->getEndLine(); |
|
225 | - $length = $end_line - $start_line; |
|
226 | - $source = file($filename); |
|
227 | - $body = implode("", array_slice($source, $start_line, $length)); |
|
228 | - $body = trim(preg_replace('/\s+/', '', $body)); |
|
214 | + /** |
|
215 | + * Get the given method body code. |
|
216 | + * |
|
217 | + * @param object $reflectionMethod |
|
218 | + * @return string |
|
219 | + */ |
|
220 | + protected function getMethodBody($reflectionMethod) |
|
221 | + { |
|
222 | + $filename = $reflectionMethod->getFileName(); |
|
223 | + $start_line = $reflectionMethod->getStartLine() - 1; |
|
224 | + $end_line = $reflectionMethod->getEndLine(); |
|
225 | + $length = $end_line - $start_line; |
|
226 | + $source = file($filename); |
|
227 | + $body = implode("", array_slice($source, $start_line, $length)); |
|
228 | + $body = trim(preg_replace('/\s+/', '', $body)); |
|
229 | 229 | |
230 | - return $body; |
|
231 | - } |
|
230 | + return $body; |
|
231 | + } |
|
232 | 232 | |
233 | - /** |
|
234 | - * Get example object of all availble models. |
|
235 | - * |
|
236 | - * @param string $modelName |
|
237 | - * @param array $docData |
|
238 | - * @return string |
|
239 | - */ |
|
240 | - protected function getModels($modelName, &$docData, $reflectionClass) |
|
241 | - { |
|
242 | - if ($modelName && ! Arr::has($docData['models'], $modelName)) { |
|
243 | - $modelClass = get_class(call_user_func_array("\Core::{$modelName}", [])->model); |
|
244 | - $model = factory($modelClass)->make(); |
|
233 | + /** |
|
234 | + * Get example object of all availble models. |
|
235 | + * |
|
236 | + * @param string $modelName |
|
237 | + * @param array $docData |
|
238 | + * @return string |
|
239 | + */ |
|
240 | + protected function getModels($modelName, &$docData, $reflectionClass) |
|
241 | + { |
|
242 | + if ($modelName && ! Arr::has($docData['models'], $modelName)) { |
|
243 | + $modelClass = get_class(call_user_func_array("\Core::{$modelName}", [])->model); |
|
244 | + $model = factory($modelClass)->make(); |
|
245 | 245 | |
246 | - $property = $reflectionClass->getProperty('modelResource'); |
|
247 | - $property->setAccessible(true); |
|
248 | - $modelResource = $property->getValue(\App::make($reflectionClass->getName())); |
|
249 | - $modelResource = new $modelResource($model); |
|
250 | - $modelArr = $modelResource->toArray([]); |
|
246 | + $property = $reflectionClass->getProperty('modelResource'); |
|
247 | + $property->setAccessible(true); |
|
248 | + $modelResource = $property->getValue(\App::make($reflectionClass->getName())); |
|
249 | + $modelResource = new $modelResource($model); |
|
250 | + $modelArr = $modelResource->toArray([]); |
|
251 | 251 | |
252 | - foreach ($modelArr as $key => $attr) { |
|
253 | - if (is_object($attr) && $attr->resource instanceof \Illuminate\Http\Resources\MissingValue) { |
|
254 | - unset($modelArr[$key]); |
|
255 | - } |
|
256 | - } |
|
252 | + foreach ($modelArr as $key => $attr) { |
|
253 | + if (is_object($attr) && $attr->resource instanceof \Illuminate\Http\Resources\MissingValue) { |
|
254 | + unset($modelArr[$key]); |
|
255 | + } |
|
256 | + } |
|
257 | 257 | |
258 | - $docData['models'][$modelName] = json_encode($modelArr, JSON_PRETTY_PRINT); |
|
259 | - } |
|
260 | - } |
|
258 | + $docData['models'][$modelName] = json_encode($modelArr, JSON_PRETTY_PRINT); |
|
259 | + } |
|
260 | + } |
|
261 | 261 | |
262 | - /** |
|
263 | - * Get the route response object type. |
|
264 | - * |
|
265 | - * @param string $modelName |
|
266 | - * @param string $method |
|
267 | - * @param string $returnDocBlock |
|
268 | - * @return array |
|
269 | - */ |
|
270 | - protected function getResponseObject($modelName, $method, $returnDocBlock) |
|
271 | - { |
|
272 | - $config = \CoreConfig::getConfig(); |
|
273 | - $relations = Arr::has($config['relations'], $modelName) ? Arr::has($config['relations'][$modelName], $method) ? $config['relations'][$modelName] : false : false; |
|
274 | - $modelName = call_user_func_array("\Core::{$returnDocBlock}", []) ? $returnDocBlock : $modelName; |
|
262 | + /** |
|
263 | + * Get the route response object type. |
|
264 | + * |
|
265 | + * @param string $modelName |
|
266 | + * @param string $method |
|
267 | + * @param string $returnDocBlock |
|
268 | + * @return array |
|
269 | + */ |
|
270 | + protected function getResponseObject($modelName, $method, $returnDocBlock) |
|
271 | + { |
|
272 | + $config = \CoreConfig::getConfig(); |
|
273 | + $relations = Arr::has($config['relations'], $modelName) ? Arr::has($config['relations'][$modelName], $method) ? $config['relations'][$modelName] : false : false; |
|
274 | + $modelName = call_user_func_array("\Core::{$returnDocBlock}", []) ? $returnDocBlock : $modelName; |
|
275 | 275 | |
276 | - return $relations ? [$modelName => $relations && $relations[$method] ? $relations[$method] : []] : false; |
|
277 | - } |
|
276 | + return $relations ? [$modelName => $relations && $relations[$method] ? $relations[$method] : []] : false; |
|
277 | + } |
|
278 | 278 | } |
@@ -2,107 +2,107 @@ |
||
2 | 2 | |
3 | 3 | interface BaseServiceInterface |
4 | 4 | { |
5 | - /** |
|
6 | - * Fetch all records with relations from the storage. |
|
7 | - * |
|
8 | - * @param array $relations |
|
9 | - * @param array $sortBy |
|
10 | - * @param array $desc |
|
11 | - * @param array $columns |
|
12 | - * @return collection |
|
13 | - */ |
|
14 | - public function all($relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
5 | + /** |
|
6 | + * Fetch all records with relations from the storage. |
|
7 | + * |
|
8 | + * @param array $relations |
|
9 | + * @param array $sortBy |
|
10 | + * @param array $desc |
|
11 | + * @param array $columns |
|
12 | + * @return collection |
|
13 | + */ |
|
14 | + public function all($relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
15 | 15 | |
16 | - /** |
|
17 | - * Fetch all records with relations from storage in pages |
|
18 | - * that matche the given query. |
|
19 | - * |
|
20 | - * @param string $query |
|
21 | - * @param integer $perPage |
|
22 | - * @param array $relations |
|
23 | - * @param array $sortBy |
|
24 | - * @param array $desc |
|
25 | - * @param array $columns |
|
26 | - * @return collection |
|
27 | - */ |
|
28 | - public function search($query, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
16 | + /** |
|
17 | + * Fetch all records with relations from storage in pages |
|
18 | + * that matche the given query. |
|
19 | + * |
|
20 | + * @param string $query |
|
21 | + * @param integer $perPage |
|
22 | + * @param array $relations |
|
23 | + * @param array $sortBy |
|
24 | + * @param array $desc |
|
25 | + * @param array $columns |
|
26 | + * @return collection |
|
27 | + */ |
|
28 | + public function search($query, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
29 | 29 | |
30 | - /** |
|
31 | - * Fetch all records with relations from storage in pages. |
|
32 | - * |
|
33 | - * @param integer $perPage |
|
34 | - * @param array $relations |
|
35 | - * @param array $sortBy |
|
36 | - * @param array $desc |
|
37 | - * @param array $columns |
|
38 | - * @return collection |
|
39 | - */ |
|
40 | - public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
30 | + /** |
|
31 | + * Fetch all records with relations from storage in pages. |
|
32 | + * |
|
33 | + * @param integer $perPage |
|
34 | + * @param array $relations |
|
35 | + * @param array $sortBy |
|
36 | + * @param array $desc |
|
37 | + * @param array $columns |
|
38 | + * @return collection |
|
39 | + */ |
|
40 | + public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
41 | 41 | |
42 | - /** |
|
43 | - * Fetch all records with relations based on |
|
44 | - * the given condition from storage in pages. |
|
45 | - * |
|
46 | - * @param array $conditions array of conditions |
|
47 | - * @param integer $perPage |
|
48 | - * @param array $relations |
|
49 | - * @param array $sortBy |
|
50 | - * @param array $desc |
|
51 | - * @param array $columns |
|
52 | - * @return collection |
|
53 | - */ |
|
54 | - public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
42 | + /** |
|
43 | + * Fetch all records with relations based on |
|
44 | + * the given condition from storage in pages. |
|
45 | + * |
|
46 | + * @param array $conditions array of conditions |
|
47 | + * @param integer $perPage |
|
48 | + * @param array $relations |
|
49 | + * @param array $sortBy |
|
50 | + * @param array $desc |
|
51 | + * @param array $columns |
|
52 | + * @return collection |
|
53 | + */ |
|
54 | + public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
55 | 55 | |
56 | - /** |
|
57 | - * Save the given model/models to the storage. |
|
58 | - * |
|
59 | - * @param array $data |
|
60 | - * @return mixed |
|
61 | - */ |
|
62 | - public function save(array $data); |
|
56 | + /** |
|
57 | + * Save the given model/models to the storage. |
|
58 | + * |
|
59 | + * @param array $data |
|
60 | + * @return mixed |
|
61 | + */ |
|
62 | + public function save(array $data); |
|
63 | 63 | |
64 | - /** |
|
65 | - * Delete record from the storage based on the given |
|
66 | - * condition. |
|
67 | - * |
|
68 | - * @param var $value condition value |
|
69 | - * @param string $attribute condition column name |
|
70 | - * @return integer affected rows |
|
71 | - */ |
|
72 | - public function delete($value, $attribute = 'id'); |
|
64 | + /** |
|
65 | + * Delete record from the storage based on the given |
|
66 | + * condition. |
|
67 | + * |
|
68 | + * @param var $value condition value |
|
69 | + * @param string $attribute condition column name |
|
70 | + * @return integer affected rows |
|
71 | + */ |
|
72 | + public function delete($value, $attribute = 'id'); |
|
73 | 73 | |
74 | - /** |
|
75 | - * Fetch records from the storage based on the given |
|
76 | - * id. |
|
77 | - * |
|
78 | - * @param integer $id |
|
79 | - * @param array $relations |
|
80 | - * @param array $columns |
|
81 | - * @return object |
|
82 | - */ |
|
83 | - public function find($id, $relations = [], $columns = array('*')); |
|
74 | + /** |
|
75 | + * Fetch records from the storage based on the given |
|
76 | + * id. |
|
77 | + * |
|
78 | + * @param integer $id |
|
79 | + * @param array $relations |
|
80 | + * @param array $columns |
|
81 | + * @return object |
|
82 | + */ |
|
83 | + public function find($id, $relations = [], $columns = array('*')); |
|
84 | 84 | |
85 | - /** |
|
86 | - * Fetch records from the storage based on the given |
|
87 | - * condition. |
|
88 | - * |
|
89 | - * @param array $conditions array of conditions |
|
90 | - * @param array $relations |
|
91 | - * @param array $sortBy |
|
92 | - * @param array $desc |
|
93 | - * @param array $columns |
|
94 | - * @return collection |
|
95 | - */ |
|
96 | - public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
85 | + /** |
|
86 | + * Fetch records from the storage based on the given |
|
87 | + * condition. |
|
88 | + * |
|
89 | + * @param array $conditions array of conditions |
|
90 | + * @param array $relations |
|
91 | + * @param array $sortBy |
|
92 | + * @param array $desc |
|
93 | + * @param array $columns |
|
94 | + * @return collection |
|
95 | + */ |
|
96 | + public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
97 | 97 | |
98 | - /** |
|
99 | - * Fetch the first record fro the storage based on the given |
|
100 | - * condition. |
|
101 | - * |
|
102 | - * @param array $conditions array of conditions |
|
103 | - * @param array $relations |
|
104 | - * @param array $columns |
|
105 | - * @return object |
|
106 | - */ |
|
107 | - public function first($conditions, $relations = [], $columns = array('*')); |
|
98 | + /** |
|
99 | + * Fetch the first record fro the storage based on the given |
|
100 | + * condition. |
|
101 | + * |
|
102 | + * @param array $conditions array of conditions |
|
103 | + * @param array $relations |
|
104 | + * @param array $columns |
|
105 | + * @return object |
|
106 | + */ |
|
107 | + public function first($conditions, $relations = [], $columns = array('*')); |
|
108 | 108 | } |
@@ -6,27 +6,27 @@ |
||
6 | 6 | |
7 | 7 | class AssignRelationsSeeder extends Seeder |
8 | 8 | { |
9 | - /** |
|
10 | - * Run the database seeds. |
|
11 | - * |
|
12 | - * @return void |
|
13 | - */ |
|
14 | - public function run() |
|
15 | - { |
|
16 | - $adminRoleId = \DB::table('roles')->where('name', 'admin')->select('id')->first()->id; |
|
9 | + /** |
|
10 | + * Run the database seeds. |
|
11 | + * |
|
12 | + * @return void |
|
13 | + */ |
|
14 | + public function run() |
|
15 | + { |
|
16 | + $adminRoleId = \DB::table('roles')->where('name', 'admin')->select('id')->first()->id; |
|
17 | 17 | |
18 | - /** |
|
19 | - * Assign the permissions to the admin role. |
|
20 | - */ |
|
21 | - \DB::table('permissions')->orderBy('created_at', 'asc')->whereIn('model', ['setting'])->each(function ($permission) use ($adminRoleId) { |
|
22 | - \DB::table('permission_role')->insert( |
|
23 | - [ |
|
24 | - 'permission_id' => $permission->id, |
|
25 | - 'role_id' => $adminRoleId, |
|
26 | - 'created_at' => \DB::raw('NOW()'), |
|
27 | - 'updated_at' => \DB::raw('NOW()') |
|
28 | - ] |
|
29 | - ); |
|
30 | - }); |
|
31 | - } |
|
18 | + /** |
|
19 | + * Assign the permissions to the admin role. |
|
20 | + */ |
|
21 | + \DB::table('permissions')->orderBy('created_at', 'asc')->whereIn('model', ['setting'])->each(function ($permission) use ($adminRoleId) { |
|
22 | + \DB::table('permission_role')->insert( |
|
23 | + [ |
|
24 | + 'permission_id' => $permission->id, |
|
25 | + 'role_id' => $adminRoleId, |
|
26 | + 'created_at' => \DB::raw('NOW()'), |
|
27 | + 'updated_at' => \DB::raw('NOW()') |
|
28 | + ] |
|
29 | + ); |
|
30 | + }); |
|
31 | + } |
|
32 | 32 | } |
@@ -18,7 +18,7 @@ |
||
18 | 18 | /** |
19 | 19 | * Assign the permissions to the admin role. |
20 | 20 | */ |
21 | - \DB::table('permissions')->orderBy('created_at', 'asc')->whereIn('model', ['setting'])->each(function ($permission) use ($adminRoleId) { |
|
21 | + \DB::table('permissions')->orderBy('created_at', 'asc')->whereIn('model', ['setting'])->each(function($permission) use ($adminRoleId) { |
|
22 | 22 | \DB::table('permission_role')->insert( |
23 | 23 | [ |
24 | 24 | 'permission_id' => $permission->id, |