@@ -18,10 +18,10 @@ |
||
| 18 | 18 | { |
| 19 | 19 | foreach ($this->getRepoNameSpace() as $repoNameSpace) |
| 20 | 20 | { |
| 21 | - $class = rtrim($repoNameSpace, '\\') . '\\' . ucfirst(str_singular($name)) . 'Repository'; |
|
| 21 | + $class = rtrim($repoNameSpace, '\\').'\\'.ucfirst(str_singular($name)).'Repository'; |
|
| 22 | 22 | if (class_exists($class)) |
| 23 | 23 | { |
| 24 | - \App::singleton($class, function ($app) use ($class) { |
|
| 24 | + \App::singleton($class, function($app) use ($class) { |
|
| 25 | 25 | |
| 26 | 26 | return new \App\Modules\V1\Core\Decorators\CachingDecorator(new $class, $app['cache.store']); |
| 27 | 27 | }); |
@@ -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 | ]; |
@@ -34,7 +34,7 @@ |
||
| 34 | 34 | $this->validationRules = property_exists($this, 'validationRules') ? $this->validationRules : false; |
| 35 | 35 | $this->skipPermissionCheck = property_exists($this, 'skipPermissionCheck') ? $this->skipPermissionCheck : []; |
| 36 | 36 | $this->skipLoginCheck = property_exists($this, 'skipLoginCheck') ? $this->skipLoginCheck : []; |
| 37 | - $route = explode('@',\Route::currentRouteAction())[1]; |
|
| 37 | + $route = explode('@', \Route::currentRouteAction())[1]; |
|
| 38 | 38 | |
| 39 | 39 | $this->checkPermission($route); |
| 40 | 40 | $this->setRelations($route); |
@@ -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 | |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | $user = \Core::users()->find(\JWTAuth::parseToken()->authenticate()->id, $relations); |
| 27 | 27 | foreach ($user->groups()->get() as $group) |
| 28 | 28 | { |
| 29 | - $group->permissions->each(function ($permission) use (&$permissions){ |
|
| 29 | + $group->permissions->each(function($permission) use (&$permissions){ |
|
| 30 | 30 | $permissions[$permission->model][$permission->id] = $permission->name; |
| 31 | 31 | }); |
| 32 | 32 | } |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | * @param boolean $user |
| 45 | 45 | * @return boolean |
| 46 | 46 | */ |
| 47 | - public function can($nameOfPermission, $model, $user = false ) |
|
| 47 | + public function can($nameOfPermission, $model, $user = false) |
|
| 48 | 48 | { |
| 49 | 49 | $user = $user ?: \JWTAuth::parseToken()->authenticate(); |
| 50 | 50 | $permissions = []; |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | \ErrorHandler::tokenExpired(); |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - $user->groups->pluck('permissions')->each(function ($permission) use (&$permissions, $model){ |
|
| 57 | + $user->groups->pluck('permissions')->each(function($permission) use (&$permissions, $model){ |
|
| 58 | 58 | $permissions = array_merge($permissions, $permission->where('model', $model)->pluck('name')->toArray()); |
| 59 | 59 | }); |
| 60 | 60 | |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | */ |
| 83 | 83 | public function assignGroups($user_id, $group_ids) |
| 84 | 84 | { |
| 85 | - \DB::transaction(function () use ($user_id, $group_ids) { |
|
| 85 | + \DB::transaction(function() use ($user_id, $group_ids) { |
|
| 86 | 86 | $user = $this->find($user_id); |
| 87 | 87 | $user->groups()->detach(); |
| 88 | 88 | $user->groups()->attach($group_ids); |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | $url = $this->config['resetLink']; |
| 246 | 246 | $token = \Password::getRepository()->create($user); |
| 247 | 247 | |
| 248 | - \Mail::send('Acl:resetpassword', ['user' => $user, 'url' => $url, 'token' => $token], function ($m) use ($user) { |
|
| 248 | + \Mail::send('Acl:resetpassword', ['user' => $user, 'url' => $url, 'token' => $token], function($m) use ($user) { |
|
| 249 | 249 | $m->to($user->email, $user->name)->subject('Your Password Reset Link'); |
| 250 | 250 | }); |
| 251 | 251 | } |
@@ -259,7 +259,7 @@ discard block |
||
| 259 | 259 | public function resetPassword($credentials) |
| 260 | 260 | { |
| 261 | 261 | $token = false; |
| 262 | - $response = \Password::reset($credentials, function ($user, $password) use (&$token) { |
|
| 262 | + $response = \Password::reset($credentials, function($user, $password) use (&$token) { |
|
| 263 | 263 | $user->password = bcrypt($password); |
| 264 | 264 | $user->save(); |
| 265 | 265 | |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -$factory->define(App\Modules\V1\Core\Settings::class, function (Faker\Generator $faker) { |
|
| 3 | +$factory->define(App\Modules\V1\Core\Settings::class, function(Faker\Generator $faker) { |
|
| 4 | 4 | return [ |
| 5 | 5 | 'id' => $faker->randomDigitNotNull(), |
| 6 | 6 | 'name' => $faker->randomElement(['Company Name', 'Title', 'Header Image']), |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -$factory->define(App\Modules\V1\Core\Log::class, function (Faker\Generator $faker) { |
|
| 3 | +$factory->define(App\Modules\V1\Core\Log::class, function(Faker\Generator $faker) { |
|
| 4 | 4 | return [ |
| 5 | 5 | 'id' => $faker->randomDigitNotNull(), |
| 6 | 6 | 'action' => $faker->randomElement(['create', 'delete', 'update']), |