@@ -29,7 +29,7 @@ |
||
29 | 29 | |
30 | 30 | public function groups() |
31 | 31 | { |
32 | - return $this->belongsToMany('\App\Modules\V1\Acl\AclGroup','groups_permissions','permission_id','group_id')->whereNull('groups_permissions.deleted_at')->withTimestamps(); |
|
32 | + return $this->belongsToMany('\App\Modules\V1\Acl\AclGroup', 'groups_permissions', 'permission_id', 'group_id')->whereNull('groups_permissions.deleted_at')->withTimestamps(); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | public static function boot() |
@@ -13,14 +13,14 @@ |
||
13 | 13 | * to preform actions like (add, edit ... etc). |
14 | 14 | * @var string |
15 | 15 | */ |
16 | - protected $model = 'groups'; |
|
16 | + protected $model = 'groups'; |
|
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|unique:groups,name,{id}' |
25 | 25 | ]; |
26 | 26 |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | use SoftDeletes; |
10 | 10 | protected $table = 'users'; |
11 | 11 | protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
12 | - protected $hidden = ['password', 'remember_token','deleted_at']; |
|
12 | + protected $hidden = ['password', 'remember_token', 'deleted_at']; |
|
13 | 13 | protected $guarded = ['id']; |
14 | 14 | protected $fillable = ['first_name', 'last_name', 'user_name', 'address', 'email', 'password']; |
15 | 15 | protected $appends = ['permissions']; |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | |
48 | 48 | public function groups() |
49 | 49 | { |
50 | - return $this->belongsToMany('\App\Modules\V1\Acl\AclGroup','users_groups','user_id','group_id')->whereNull('users_groups.deleted_at')->withTimestamps(); |
|
50 | + return $this->belongsToMany('\App\Modules\V1\Acl\AclGroup', 'users_groups', 'user_id', 'group_id')->whereNull('users_groups.deleted_at')->withTimestamps(); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | public function getPermissionsAttribute() |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | $permissions = []; |
56 | 56 | foreach ($this->groups as $group) |
57 | 57 | { |
58 | - $group->permissions->each(function ($permission) use (&$permissions){ |
|
58 | + $group->permissions->each(function($permission) use (&$permissions){ |
|
59 | 59 | $permissions[$permission->model][$permission->id] = $permission->name; |
60 | 60 | }); |
61 | 61 | } |
@@ -70,7 +70,7 @@ |
||
70 | 70 | |
71 | 71 | public function notFound($text) |
72 | 72 | { |
73 | - $error = ['status' => 404, 'message' => 'The requested ' . $text . ' not found']; |
|
73 | + $error = ['status' => 404, 'message' => 'The requested '.$text.' not found']; |
|
74 | 74 | abort($error['status'], $error['message']); |
75 | 75 | } |
76 | 76 |
@@ -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', 'register', 'sendreset', 'resetpassword']; |
|
29 | + protected $skipLoginCheck = ['login', 'register', 'sendreset', 'resetpassword']; |
|
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 | 'email' => 'required|email|unique:users,email,{id}', |
38 | 38 | 'password' => 'min:6' |
39 | 39 | ]; |
@@ -23,11 +23,11 @@ discard block |
||
23 | 23 | * @param boolean $user |
24 | 24 | * @return boolean |
25 | 25 | */ |
26 | - public function can($nameOfPermission, $model, $user = false ) |
|
26 | + public function can($nameOfPermission, $model, $user = false) |
|
27 | 27 | { |
28 | 28 | $user = $user ?: \JWTAuth::parseToken()->authenticate(); |
29 | 29 | $permissions = []; |
30 | - \Core::users()->find($user->id, ['groups.permissions'])->groups->lists('permissions')->each(function ($permission) use (&$permissions, $model){ |
|
30 | + \Core::users()->find($user->id, ['groups.permissions'])->groups->lists('permissions')->each(function($permission) use (&$permissions, $model){ |
|
31 | 31 | $permissions = array_merge($permissions, $permission->where('model', $model)->lists('name')->toArray()); |
32 | 32 | }); |
33 | 33 | |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | */ |
56 | 56 | public function assignGroups($user_id, $group_ids) |
57 | 57 | { |
58 | - \DB::transaction(function () use ($user_id, $group_ids) { |
|
58 | + \DB::transaction(function() use ($user_id, $group_ids) { |
|
59 | 59 | $user = \Core::users()->find($user_id); |
60 | 60 | $user->groups()->detach(); |
61 | 61 | $user->groups()->attach($group_ids); |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | */ |
188 | 188 | public function sendReset($email) |
189 | 189 | { |
190 | - $response = \Password::sendResetLink($email, function (\Illuminate\Mail\Message $message) { |
|
190 | + $response = \Password::sendResetLink($email, function(\Illuminate\Mail\Message $message) { |
|
191 | 191 | $message->subject('Your Password Reset Link'); |
192 | 192 | }); |
193 | 193 | |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | public function resetPassword($credentials) |
208 | 208 | { |
209 | 209 | $token = false; |
210 | - $response = \Password::reset($credentials, function ($user, $password) use (&$token) { |
|
210 | + $response = \Password::reset($credentials, function($user, $password) use (&$token) { |
|
211 | 211 | $user->password = $password; |
212 | 212 | $user->save(); |
213 | 213 |
@@ -12,7 +12,7 @@ |
||
12 | 12 | */ |
13 | 13 | public function up() |
14 | 14 | { |
15 | - Schema::create('password_resets', function (Blueprint $table) { |
|
15 | + Schema::create('password_resets', function(Blueprint $table) { |
|
16 | 16 | $table->string('email')->index(); |
17 | 17 | $table->string('token')->index(); |
18 | 18 | $table->timestamp('created_at'); |
@@ -12,9 +12,9 @@ |
||
12 | 12 | */ |
13 | 13 | public function up() |
14 | 14 | { |
15 | - Schema::create('users', function (Blueprint $table) { |
|
15 | + Schema::create('users', function(Blueprint $table) { |
|
16 | 16 | $table->increments('id'); |
17 | - $table->string('name',100)->nullable(); |
|
17 | + $table->string('name', 100)->nullable(); |
|
18 | 18 | $table->string('email')->unique(); |
19 | 19 | $table->string('password', 60); |
20 | 20 | $table->boolean('blocked', 0); |
@@ -63,19 +63,19 @@ 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 | /** |
69 | 69 | * Use the first element in the model columns to construct the first condition. |
70 | 70 | */ |
71 | - $q->where(\DB::raw('LOWER(CAST(' .array_shift($conditionColumns). ' AS TEXT))'), 'LIKE', '%' . strtolower($query) . '%'); |
|
71 | + $q->where(\DB::raw('LOWER(CAST('.array_shift($conditionColumns).' AS TEXT))'), 'LIKE', '%'.strtolower($query).'%'); |
|
72 | 72 | |
73 | 73 | /** |
74 | 74 | * Loop through the rest of the columns to construct or where conditions. |
75 | 75 | */ |
76 | 76 | foreach ($conditionColumns as $column) |
77 | 77 | { |
78 | - $q->orWhere(\DB::raw('LOWER(CAST(' . $column . ' AS TEXT))'), 'LIKE', '%' . strtolower($query) . '%'); |
|
78 | + $q->orWhere(\DB::raw('LOWER(CAST('.$column.' AS TEXT))'), 'LIKE', '%'.strtolower($query).'%'); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
@@ -96,9 +96,9 @@ discard block |
||
96 | 96 | /** |
97 | 97 | * Construct the relation condition. |
98 | 98 | */ |
99 | - $q->orWhereHas($relation, function ($subModel) use ($query, $relation){ |
|
99 | + $q->orWhereHas($relation, function($subModel) use ($query, $relation){ |
|
100 | 100 | |
101 | - $subModel->where(function ($q) use ($query, $relation){ |
|
101 | + $subModel->where(function($q) use ($query, $relation){ |
|
102 | 102 | |
103 | 103 | /** |
104 | 104 | * Get columns of the relation. |
@@ -108,14 +108,14 @@ discard block |
||
108 | 108 | /** |
109 | 109 | * Use the first element in the relation model columns to construct the first condition. |
110 | 110 | */ |
111 | - $q->where(\DB::raw('LOWER(CAST(' . array_shift($subConditionColumns) . ' AS TEXT))'), 'LIKE', '%' . strtolower($query) . '%'); |
|
111 | + $q->where(\DB::raw('LOWER(CAST('.array_shift($subConditionColumns).' AS TEXT))'), 'LIKE', '%'.strtolower($query).'%'); |
|
112 | 112 | |
113 | 113 | /** |
114 | 114 | * Loop through the rest of the columns to construct or where conditions. |
115 | 115 | */ |
116 | 116 | foreach ($subConditionColumns as $subConditionColumn) |
117 | 117 | { |
118 | - $q->orWhere(\DB::raw('LOWER(CAST(' . $subConditionColumn . ' AS TEXT))'), 'LIKE', '%' . strtolower($query) . '%'); |
|
118 | + $q->orWhere(\DB::raw('LOWER(CAST('.$subConditionColumn.' AS TEXT))'), 'LIKE', '%'.strtolower($query).'%'); |
|
119 | 119 | } |
120 | 120 | }); |
121 | 121 | |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | $relations = []; |
178 | 178 | $with = []; |
179 | 179 | |
180 | - \DB::transaction(function () use (&$model, &$relations, &$with, $data, $saveLog, $modelClass) { |
|
180 | + \DB::transaction(function() use (&$model, &$relations, &$with, $data, $saveLog, $modelClass) { |
|
181 | 181 | /** |
182 | 182 | * If the id is present in the data then select the model for updating, |
183 | 183 | * else create new model. |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | $model = array_key_exists('id', $data) ? $modelClass->lockForUpdate()->find($data['id']) : new $modelClass; |
187 | 187 | if ( ! $model) |
188 | 188 | { |
189 | - \ErrorHandler::notFound(class_basename($modelClass) . ' with id : ' . $data['id']); |
|
189 | + \ErrorHandler::notFound(class_basename($modelClass).' with id : '.$data['id']); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | /** |
@@ -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 | } |
@@ -288,7 +288,7 @@ discard block |
||
288 | 288 | */ |
289 | 289 | if ( ! $relationModel) |
290 | 290 | { |
291 | - \ErrorHandler::notFound(class_basename($relationBaseModel) . ' with id : ' . $value['id']); |
|
291 | + \ErrorHandler::notFound(class_basename($relationBaseModel).' with id : '.$value['id']); |
|
292 | 292 | } |
293 | 293 | |
294 | 294 | /** |
@@ -425,11 +425,11 @@ discard block |
||
425 | 425 | { |
426 | 426 | if ($attribute == 'id') |
427 | 427 | { |
428 | - \DB::transaction(function () use ($value, $attribute, &$result, $saveLog) { |
|
428 | + \DB::transaction(function() use ($value, $attribute, &$result, $saveLog) { |
|
429 | 429 | $model = $this->model->lockForUpdate()->find($value); |
430 | 430 | if ( ! $model) |
431 | 431 | { |
432 | - \ErrorHandler::notFound(class_basename($this->model) . ' with id : ' . $value); |
|
432 | + \ErrorHandler::notFound(class_basename($this->model).' with id : '.$value); |
|
433 | 433 | } |
434 | 434 | |
435 | 435 | $model->delete(); |
@@ -438,8 +438,8 @@ discard block |
||
438 | 438 | } |
439 | 439 | else |
440 | 440 | { |
441 | - \DB::transaction(function () use ($value, $attribute, &$result, $saveLog) { |
|
442 | - call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function ($model){ |
|
441 | + \DB::transaction(function() use ($value, $attribute, &$result, $saveLog) { |
|
442 | + call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function($model) { |
|
443 | 443 | $model->delete(); |
444 | 444 | $saveLog ? \Logging::saveLog('delete', class_basename($this->model), $this->getModel(), $model->id, $model) : false; |
445 | 445 | }); |
@@ -476,7 +476,7 @@ discard block |
||
476 | 476 | { |
477 | 477 | $conditions = $this->constructConditions($conditions); |
478 | 478 | $sort = $desc ? 'desc' : 'asc'; |
479 | - return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->get($columns); |
|
479 | + return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->get($columns); |
|
480 | 480 | } |
481 | 481 | |
482 | 482 | /** |
@@ -507,21 +507,21 @@ discard block |
||
507 | 507 | { |
508 | 508 | if ($key == 'and') |
509 | 509 | { |
510 | - $conditionString .= str_replace('{op}', 'and', $this->constructConditions($value)['conditionString']) . ' {op} '; |
|
510 | + $conditionString .= str_replace('{op}', 'and', $this->constructConditions($value)['conditionString']).' {op} '; |
|
511 | 511 | $conditionValues = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']); |
512 | 512 | } |
513 | 513 | else if ($key == 'or') |
514 | 514 | { |
515 | - $conditionString .= str_replace('{op}', 'or', $this->constructConditions($value)['conditionString']) . ' {op} '; |
|
515 | + $conditionString .= str_replace('{op}', 'or', $this->constructConditions($value)['conditionString']).' {op} '; |
|
516 | 516 | $conditionValues = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']); |
517 | 517 | } |
518 | 518 | else |
519 | 519 | { |
520 | - $conditionString .= $key . '=? {op} '; |
|
520 | + $conditionString .= $key.'=? {op} '; |
|
521 | 521 | $conditionValues[] = $value; |
522 | 522 | } |
523 | 523 | } |
524 | - $conditionString = '(' . rtrim($conditionString, '{op} ') . ')'; |
|
524 | + $conditionString = '('.rtrim($conditionString, '{op} ').')'; |
|
525 | 525 | return ['conditionString' => $conditionString, 'conditionValues' => $conditionValues]; |
526 | 526 | } |
527 | 527 |