@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | * to preform actions like (add, edit ... etc). |
13 | 13 | * @var string |
14 | 14 | */ |
15 | - protected $model = 'users'; |
|
15 | + protected $model = 'users'; |
|
16 | 16 | |
17 | 17 | /** |
18 | 18 | * List of all route actions that the base api controller |
@@ -26,14 +26,14 @@ discard block |
||
26 | 26 | * will skip login check for them. |
27 | 27 | * @var array |
28 | 28 | */ |
29 | - protected $skipLoginCheck = ['login', 'loginSocial', 'register', 'sendreset', 'resetpassword', 'refreshtoken']; |
|
29 | + protected $skipLoginCheck = ['login', 'loginSocial', 'register', 'sendreset', 'resetpassword', 'refreshtoken']; |
|
30 | 30 | |
31 | 31 | /** |
32 | 32 | * The validations rules used by the base api controller |
33 | 33 | * to check before add. |
34 | 34 | * @var array |
35 | 35 | */ |
36 | - protected $validationRules = [ |
|
36 | + protected $validationRules = [ |
|
37 | 37 | 'name' => 'nullable|string|unique:users,name,{id},id,name,NOT_NULL', |
38 | 38 | 'email' => 'required|email|unique:users,email,{id},id,email,NOT_NULL', |
39 | 39 | 'password' => 'nullable|min:6' |
@@ -12,10 +12,10 @@ |
||
12 | 12 | */ |
13 | 13 | public function up() |
14 | 14 | { |
15 | - Schema::create('settings', function (Blueprint $table) { |
|
15 | + Schema::create('settings', function(Blueprint $table) { |
|
16 | 16 | $table->increments('id'); |
17 | - $table->string('name',100); |
|
18 | - $table->string('key',100)->unique(); |
|
17 | + $table->string('name', 100); |
|
18 | + $table->string('key', 100)->unique(); |
|
19 | 19 | $table->text('value')->nullable(); |
20 | 20 | $table->softDeletes(); |
21 | 21 | $table->timestamps(); |
@@ -13,14 +13,14 @@ |
||
13 | 13 | * to preform actions like (add, edit ... etc). |
14 | 14 | * @var string |
15 | 15 | */ |
16 | - protected $model = 'settings'; |
|
16 | + protected $model = 'settings'; |
|
17 | 17 | |
18 | 18 | /** |
19 | 19 | * The validations rules used by the base api controller |
20 | 20 | * to check before add. |
21 | 21 | * @var array |
22 | 22 | */ |
23 | - protected $validationRules = [ |
|
23 | + protected $validationRules = [ |
|
24 | 24 | 'name' => 'required|string|max:100', |
25 | 25 | 'value' => 'required|string' |
26 | 26 | ]; |
@@ -63,14 +63,14 @@ discard block |
||
63 | 63 | /** |
64 | 64 | * Construct the select conditions for the model. |
65 | 65 | */ |
66 | - $model->where(function ($q) use ($query, $conditionColumns, $relations){ |
|
66 | + $model->where(function($q) use ($query, $conditionColumns, $relations){ |
|
67 | 67 | |
68 | 68 | if (count($conditionColumns)) |
69 | 69 | { |
70 | 70 | /** |
71 | 71 | * Use the first element in the model columns to construct the first condition. |
72 | 72 | */ |
73 | - $q->where(\DB::raw('LOWER(' . array_shift($conditionColumns) . ')'), 'LIKE', '%' . strtolower($query) . '%'); |
|
73 | + $q->where(\DB::raw('LOWER('.array_shift($conditionColumns).')'), 'LIKE', '%'.strtolower($query).'%'); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | /** |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | */ |
79 | 79 | foreach ($conditionColumns as $column) |
80 | 80 | { |
81 | - $q->orWhere(\DB::raw('LOWER(' . $column . ')'), 'LIKE', '%' . strtolower($query) . '%'); |
|
81 | + $q->orWhere(\DB::raw('LOWER('.$column.')'), 'LIKE', '%'.strtolower($query).'%'); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
@@ -99,9 +99,9 @@ discard block |
||
99 | 99 | /** |
100 | 100 | * Construct the relation condition. |
101 | 101 | */ |
102 | - $q->orWhereHas($relation, function ($subModel) use ($query, $relation){ |
|
102 | + $q->orWhereHas($relation, function($subModel) use ($query, $relation){ |
|
103 | 103 | |
104 | - $subModel->where(function ($q) use ($query, $relation){ |
|
104 | + $subModel->where(function($q) use ($query, $relation){ |
|
105 | 105 | |
106 | 106 | /** |
107 | 107 | * Get columns of the relation. |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | /** |
114 | 114 | * Use the first element in the relation model columns to construct the first condition. |
115 | 115 | */ |
116 | - $q->where(\DB::raw('LOWER(' . array_shift($subConditionColumns) . ')'), 'LIKE', '%' . strtolower($query) . '%'); |
|
116 | + $q->where(\DB::raw('LOWER('.array_shift($subConditionColumns).')'), 'LIKE', '%'.strtolower($query).'%'); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | /** |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | */ |
122 | 122 | foreach ($subConditionColumns as $subConditionColumn) |
123 | 123 | { |
124 | - $q->orWhere(\DB::raw('LOWER(' . $subConditionColumn . ')'), 'LIKE', '%' . strtolower($query) . '%'); |
|
124 | + $q->orWhere(\DB::raw('LOWER('.$subConditionColumn.')'), 'LIKE', '%'.strtolower($query).'%'); |
|
125 | 125 | } |
126 | 126 | }); |
127 | 127 | |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | $modelClass = $this->model; |
183 | 183 | $relations = []; |
184 | 184 | |
185 | - \DB::transaction(function () use (&$model, &$relations, $data, $saveLog, $modelClass) { |
|
185 | + \DB::transaction(function() use (&$model, &$relations, $data, $saveLog, $modelClass) { |
|
186 | 186 | /** |
187 | 187 | * If the id is present in the data then select the model for updating, |
188 | 188 | * else create new model. |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | $model = array_key_exists('id', $data) ? $modelClass->lockForUpdate()->find($data['id']) : new $modelClass; |
192 | 192 | if ( ! $model) |
193 | 193 | { |
194 | - \ErrorHandler::notFound(class_basename($modelClass) . ' with id : ' . $data['id']); |
|
194 | + \ErrorHandler::notFound(class_basename($modelClass).' with id : '.$data['id']); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | /** |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | */ |
250 | 250 | if ( ! $relationModel) |
251 | 251 | { |
252 | - \ErrorHandler::notFound(class_basename($relationBaseModel) . ' with id : ' . $val['id']); |
|
252 | + \ErrorHandler::notFound(class_basename($relationBaseModel).' with id : '.$val['id']); |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | /** |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | /** |
261 | 261 | * Prevent the sub relations or attributes not in the fillable. |
262 | 262 | */ |
263 | - if (gettype($val) !== 'object' && gettype($val) !== 'array' && array_search($attr, $relationModel->getFillable(), true) !== false) |
|
263 | + if (gettype($val) !== 'object' && gettype($val) !== 'array' && array_search($attr, $relationModel->getFillable(), true) !== false) |
|
264 | 264 | { |
265 | 265 | $relationModel->$attr = $val; |
266 | 266 | } |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | */ |
291 | 291 | if ( ! $relationModel) |
292 | 292 | { |
293 | - \ErrorHandler::notFound(class_basename($relationBaseModel) . ' with id : ' . $value['id']); |
|
293 | + \ErrorHandler::notFound(class_basename($relationBaseModel).' with id : '.$value['id']); |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | foreach ($value as $relationAttribute => $relationValue) |
@@ -435,7 +435,7 @@ discard block |
||
435 | 435 | } |
436 | 436 | else |
437 | 437 | { |
438 | - call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function ($model) use ($data, $saveLog){ |
|
438 | + call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function($model) use ($data, $saveLog){ |
|
439 | 439 | $model->update($data); |
440 | 440 | $saveLog ? \Logging::saveLog('update', class_basename($this->model), $this->getModel(), $model->id, $model) : false; |
441 | 441 | }); |
@@ -454,11 +454,11 @@ discard block |
||
454 | 454 | { |
455 | 455 | if ($attribute == 'id') |
456 | 456 | { |
457 | - \DB::transaction(function () use ($value, $attribute, &$result, $saveLog) { |
|
457 | + \DB::transaction(function() use ($value, $attribute, &$result, $saveLog) { |
|
458 | 458 | $model = $this->model->lockForUpdate()->find($value); |
459 | 459 | if ( ! $model) |
460 | 460 | { |
461 | - \ErrorHandler::notFound(class_basename($this->model) . ' with id : ' . $value); |
|
461 | + \ErrorHandler::notFound(class_basename($this->model).' with id : '.$value); |
|
462 | 462 | } |
463 | 463 | |
464 | 464 | $model->delete(); |
@@ -467,8 +467,8 @@ discard block |
||
467 | 467 | } |
468 | 468 | else |
469 | 469 | { |
470 | - \DB::transaction(function () use ($value, $attribute, &$result, $saveLog) { |
|
471 | - call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function ($model) use ($saveLog){ |
|
470 | + \DB::transaction(function() use ($value, $attribute, &$result, $saveLog) { |
|
471 | + call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function($model) use ($saveLog){ |
|
472 | 472 | $model->delete(); |
473 | 473 | $saveLog ? \Logging::saveLog('delete', class_basename($this->model), $this->getModel(), $model->id, $model) : false; |
474 | 474 | }); |
@@ -505,7 +505,7 @@ discard block |
||
505 | 505 | { |
506 | 506 | $conditions = $this->constructConditions($conditions, $this->model); |
507 | 507 | $sort = $desc ? 'desc' : 'asc'; |
508 | - return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->get($columns); |
|
508 | + return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->get($columns); |
|
509 | 509 | } |
510 | 510 | |
511 | 511 | /** |
@@ -545,7 +545,7 @@ discard block |
||
545 | 545 | $model->whereRaw($conditions['conditionString'], $conditions['conditionValues']); |
546 | 546 | } |
547 | 547 | |
548 | - return $model->orderBy($sortBy, $sort)->paginate($perPage, $columns);; |
|
548 | + return $model->orderBy($sortBy, $sort)->paginate($perPage, $columns); ; |
|
549 | 549 | } |
550 | 550 | |
551 | 551 | /** |
@@ -560,7 +560,7 @@ discard block |
||
560 | 560 | |
561 | 561 | if ( ! $model) |
562 | 562 | { |
563 | - \ErrorHandler::notFound(class_basename($this->model) . ' with id : ' . $id); |
|
563 | + \ErrorHandler::notFound(class_basename($this->model).' with id : '.$id); |
|
564 | 564 | } |
565 | 565 | |
566 | 566 | $model->restore(); |
@@ -580,13 +580,13 @@ discard block |
||
580 | 580 | if ($key == 'and') |
581 | 581 | { |
582 | 582 | $conditions = $this->constructConditions($value, $model); |
583 | - $conditionString .= str_replace('{op}', 'and', $conditions['conditionString']) . ' {op} '; |
|
583 | + $conditionString .= str_replace('{op}', 'and', $conditions['conditionString']).' {op} '; |
|
584 | 584 | $conditionValues = array_merge($conditionValues, $conditions['conditionValues']); |
585 | 585 | } |
586 | 586 | else if ($key == 'or') |
587 | 587 | { |
588 | 588 | $conditions = $this->constructConditions($value, $model); |
589 | - $conditionString .= str_replace('{op}', 'or', $conditions['conditionString']) . ' {op} '; |
|
589 | + $conditionString .= str_replace('{op}', 'or', $conditions['conditionString']).' {op} '; |
|
590 | 590 | $conditionValues = array_merge($conditionValues, $conditions['conditionValues']); |
591 | 591 | } |
592 | 592 | else |
@@ -611,41 +611,41 @@ discard block |
||
611 | 611 | |
612 | 612 | if (strtolower($operator) == 'between') |
613 | 613 | { |
614 | - $conditionString .= $key . ' >= ? and '; |
|
614 | + $conditionString .= $key.' >= ? and '; |
|
615 | 615 | $conditionValues[] = $value1; |
616 | 616 | |
617 | - $conditionString .= $key . ' <= ? {op} '; |
|
617 | + $conditionString .= $key.' <= ? {op} '; |
|
618 | 618 | $conditionValues[] = $value2; |
619 | 619 | } |
620 | 620 | elseif (strtolower($operator) == 'in') |
621 | 621 | { |
622 | 622 | $conditionValues = array_merge($conditionValues, $value); |
623 | 623 | $inBindingsString = rtrim(str_repeat('?,', count($value)), ','); |
624 | - $conditionString .= $key . ' in (' . rtrim($inBindingsString, ',') . ') {op} '; |
|
624 | + $conditionString .= $key.' in ('.rtrim($inBindingsString, ',').') {op} '; |
|
625 | 625 | } |
626 | 626 | elseif (strtolower($operator) == 'null') |
627 | 627 | { |
628 | - $conditionString .= $key . ' is null {op} '; |
|
628 | + $conditionString .= $key.' is null {op} '; |
|
629 | 629 | } |
630 | 630 | elseif (strtolower($operator) == 'not null') |
631 | 631 | { |
632 | - $conditionString .= $key . ' is not null {op} '; |
|
632 | + $conditionString .= $key.' is not null {op} '; |
|
633 | 633 | } |
634 | 634 | elseif (strtolower($operator) == 'has') |
635 | 635 | { |
636 | 636 | $sql = $model->withTrashed()->has($key)->toSql(); |
637 | 637 | $conditions = $this->constructConditions($value, $model->$key()->getRelated()); |
638 | - $conditionString .= rtrim(substr($sql, strpos($sql, 'exists')), ')') . ' and ' . $conditions['conditionString'] . ') {op} '; |
|
638 | + $conditionString .= rtrim(substr($sql, strpos($sql, 'exists')), ')').' and '.$conditions['conditionString'].') {op} '; |
|
639 | 639 | $conditionValues = array_merge($conditionValues, $conditions['conditionValues']); |
640 | 640 | } |
641 | 641 | else |
642 | 642 | { |
643 | - $conditionString .= $key . ' ' . $operator . ' ? {op} '; |
|
643 | + $conditionString .= $key.' '.$operator.' ? {op} '; |
|
644 | 644 | $conditionValues[] = $value; |
645 | 645 | } |
646 | 646 | } |
647 | 647 | } |
648 | - $conditionString = '(' . rtrim($conditionString, '{op} ') . ')'; |
|
648 | + $conditionString = '('.rtrim($conditionString, '{op} ').')'; |
|
649 | 649 | return ['conditionString' => $conditionString, 'conditionValues' => $conditionValues]; |
650 | 650 | } |
651 | 651 |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | { |
9 | 9 | public function index() |
10 | 10 | { |
11 | - $path = str_replace($_SERVER['DOCUMENT_ROOT'], '',str_replace('\\', '/', __FILE__)); |
|
11 | + $path = str_replace($_SERVER['DOCUMENT_ROOT'], '', str_replace('\\', '/', __FILE__)); |
|
12 | 12 | $baseUrl = str_replace('Http/Controllers/ApiDocumentController.php', '', $path); |
13 | 13 | $jsonDoc = json_decode(file_get_contents(app_path('Modules/V1/Core/Resources/api.json')), true); |
14 | 14 | $modules = $jsonDoc['modules']; |
@@ -21,27 +21,27 @@ discard block |
||
21 | 21 | ], |
22 | 22 | [ |
23 | 23 | 'title' => 'email equal [email protected] and user is blocked:', |
24 | - 'content' => ['and' => ['email' => '[email protected]','blocked' => 1]] |
|
24 | + 'content' => ['and' => ['email' => '[email protected]', 'blocked' => 1]] |
|
25 | 25 | ], |
26 | 26 | [ |
27 | 27 | 'title' => 'email equal [email protected] or user is blocked:', |
28 | - 'content' => ['or' => ['email' => '[email protected]','blocked' => 1]] |
|
28 | + 'content' => ['or' => ['email' => '[email protected]', 'blocked' => 1]] |
|
29 | 29 | ], |
30 | 30 | [ |
31 | 31 | 'title' => 'email contain John:', |
32 | - 'content' => ['email' => ['op' => 'like','val' => '%John%']] |
|
32 | + 'content' => ['email' => ['op' => 'like', 'val' => '%John%']] |
|
33 | 33 | ], |
34 | 34 | [ |
35 | 35 | 'title' => 'user created after 2016-10-25:', |
36 | - 'content' => ['created_at' => ['op' => '>','val' => '2016-10-25']] |
|
36 | + 'content' => ['created_at' => ['op' => '>', 'val' => '2016-10-25']] |
|
37 | 37 | ], |
38 | 38 | [ |
39 | 39 | 'title' => 'user created between 2016-10-20 and 2016-10-25:', |
40 | - 'content' => ['created_at' => ['op' => 'between','val1' => '2016-10-20','val2' => '2016-10-25']] |
|
40 | + 'content' => ['created_at' => ['op' => 'between', 'val1' => '2016-10-20', 'val2' => '2016-10-25']] |
|
41 | 41 | ], |
42 | 42 | [ |
43 | 43 | 'title' => 'user id in 1,2,3:', |
44 | - 'content' => ['id' => ['op' => 'in','val' => [1, 2, 3]]] |
|
44 | + 'content' => ['id' => ['op' => 'in', 'val' => [1, 2, 3]]] |
|
45 | 45 | ], |
46 | 46 | [ |
47 | 47 | 'title' => 'user name is null:', |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | ], |
54 | 54 | [ |
55 | 55 | 'title' => 'user has group admin:', |
56 | - 'content' => ['groups' => ['op' => 'has','val' => ['name' => 'Admin']]] |
|
56 | + 'content' => ['groups' => ['op' => 'has', 'val' => ['name' => 'Admin']]] |
|
57 | 57 | ] |
58 | 58 | ]; |
59 | 59 |
@@ -13,7 +13,7 @@ |
||
13 | 13 | */ |
14 | 14 | public function run() |
15 | 15 | { |
16 | - $permissions = \DB::table('permissions')->whereIn('model', ['notifications', 'pushNotificationDevices']); |
|
16 | + $permissions = \DB::table('permissions')->whereIn('model', ['notifications', 'pushNotificationDevices']); |
|
17 | 17 | \DB::table('groups_permissions')->whereIn('permission_id', $permissions->pluck('id'))->delete(); |
18 | 18 | $permissions->delete(); |
19 | 19 | } |
@@ -21,7 +21,7 @@ |
||
21 | 21 | /** |
22 | 22 | * Assign the permissions to the admin group. |
23 | 23 | */ |
24 | - \DB::table('permissions')->orderBy('created_at', 'asc')->whereIn('model', ['notifications', 'pushNotificationDevices'])->each(function ($permission) use ($adminGroupId) { |
|
24 | + \DB::table('permissions')->orderBy('created_at', 'asc')->whereIn('model', ['notifications', 'pushNotificationDevices'])->each(function($permission) use ($adminGroupId) { |
|
25 | 25 | \DB::table('groups_permissions')->insert( |
26 | 26 | [ |
27 | 27 | 'permission_id' => $permission->id, |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | public function run() |
15 | 15 | { |
16 | 16 | $adminGroupId = \DB::table('groups')->where('name', 'admin')->select('id')->first()->id; |
17 | - $adminUserId = \DB::table('users')->where('email', '[email protected]')->select('id')->first()->id; |
|
17 | + $adminUserId = \DB::table('users')->where('email', '[email protected]')->select('id')->first()->id; |
|
18 | 18 | |
19 | 19 | /** |
20 | 20 | * Assign users to groups. |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | /** |
32 | 32 | * Assign the permissions to the admin group. |
33 | 33 | */ |
34 | - \DB::table('permissions')->orderBy('created_at', 'asc')->whereIn('model', ['users', 'permissions', 'groups'])->each(function ($permission) use ($adminGroupId) { |
|
34 | + \DB::table('permissions')->orderBy('created_at', 'asc')->whereIn('model', ['users', 'permissions', 'groups'])->each(function($permission) use ($adminGroupId) { |
|
35 | 35 | \DB::table('groups_permissions')->insert( |
36 | 36 | [ |
37 | 37 | 'permission_id' => $permission->id, |
@@ -13,7 +13,7 @@ |
||
13 | 13 | */ |
14 | 14 | public function run() |
15 | 15 | { |
16 | - $permissions = \DB::table('permissions')->whereIn('model', ['reports']); |
|
16 | + $permissions = \DB::table('permissions')->whereIn('model', ['reports']); |
|
17 | 17 | \DB::table('groups_permissions')->whereIn('permission_id', $permissions->pluck('id'))->delete(); |
18 | 18 | $permissions->delete(); |
19 | 19 | } |