@@ -22,8 +22,8 @@ |
||
| 22 | 22 | public function __call(string $name, array $arguments): object |
| 23 | 23 | { |
| 24 | 24 | foreach (Module::all() as $module) { |
| 25 | - $nameSpace = 'App\\Modules\\' . $module['basename']; |
|
| 26 | - $class = $nameSpace . '\\Errors\\' . $module['basename'] . 'Errors'; |
|
| 25 | + $nameSpace = 'App\\Modules\\'.$module['basename']; |
|
| 26 | + $class = $nameSpace.'\\Errors\\'.$module['basename'].'Errors'; |
|
| 27 | 27 | |
| 28 | 28 | if (class_exists($class)) { |
| 29 | 29 | $class = App::make($class); |
@@ -23,12 +23,12 @@ |
||
| 23 | 23 | public function __call(string $name, array $arguments): object |
| 24 | 24 | { |
| 25 | 25 | foreach (Module::all() as $module) { |
| 26 | - $nameSpace = 'App\\Modules\\' . $module['basename']; |
|
| 26 | + $nameSpace = 'App\\Modules\\'.$module['basename']; |
|
| 27 | 27 | $model = ucfirst(Str::singular($name)); |
| 28 | 28 | if (count($arguments) == 1 && $arguments[0]) { |
| 29 | - $class = $nameSpace . '\\Services\\' . $model . 'Service'; |
|
| 29 | + $class = $nameSpace.'\\Services\\'.$model.'Service'; |
|
| 30 | 30 | } else { |
| 31 | - $class = $nameSpace . '\\Repositories\\' . $model . 'Repository'; |
|
| 31 | + $class = $nameSpace.'\\Repositories\\'.$model.'Repository'; |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | if (class_exists($class)) { |
@@ -75,7 +75,7 @@ |
||
| 75 | 75 | if ($this->cacheConfig && $this->cacheConfig == 'cache') { |
| 76 | 76 | $page = $this->request->get('page') !== null ? $this->request->get('page') : '1'; |
| 77 | 77 | $cacheKey = $name.$page.$this->session->get('locale').serialize($arguments); |
| 78 | - return $this->cache->tags([$this->cacheTag])->rememberForever($cacheKey, function () use ($arguments, $name) { |
|
| 78 | + return $this->cache->tags([$this->cacheTag])->rememberForever($cacheKey, function() use ($arguments, $name) { |
|
| 79 | 79 | return call_user_func_array([$this->service, $name], $arguments); |
| 80 | 80 | }); |
| 81 | 81 | } elseif ($this->cacheConfig) { |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | $model = new Model(); |
| 121 | 121 | $relations = []; |
| 122 | 122 | |
| 123 | - DB::transaction(function () use (&$model, &$relations, $data) { |
|
| 123 | + DB::transaction(function() use (&$model, &$relations, $data) { |
|
| 124 | 124 | |
| 125 | 125 | $model = $this->prepareModel($data); |
| 126 | 126 | $relations = $this->prepareRelations($data, $model); |
@@ -155,8 +155,8 @@ discard block |
||
| 155 | 155 | */ |
| 156 | 156 | public function delete(string $value, string $attribute = 'id'): bool |
| 157 | 157 | { |
| 158 | - DB::transaction(function () use ($value, $attribute) { |
|
| 159 | - $this->model->where($attribute, '=', $value)->lockForUpdate()->get()->each(function ($model) { |
|
| 158 | + DB::transaction(function() use ($value, $attribute) { |
|
| 159 | + $this->model->where($attribute, '=', $value)->lockForUpdate()->get()->each(function($model) { |
|
| 160 | 160 | $model->delete(); |
| 161 | 161 | }); |
| 162 | 162 | }); |
@@ -248,8 +248,8 @@ discard block |
||
| 248 | 248 | { |
| 249 | 249 | $model = $this->model->onlyTrashed()->find($id); |
| 250 | 250 | |
| 251 | - if (!$model) { |
|
| 252 | - Errors::notFound(class_basename($this->model) . ' with id : ' . $id); |
|
| 251 | + if ( ! $model) { |
|
| 252 | + Errors::notFound(class_basename($this->model).' with id : '.$id); |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | $model->restore(); |
@@ -274,8 +274,8 @@ discard block |
||
| 274 | 274 | * @var object |
| 275 | 275 | */ |
| 276 | 276 | $model = Arr::has($data, 'id') ? $modelClass->lockForUpdate()->find($data['id']) : new $modelClass; |
| 277 | - if (!$model) { |
|
| 278 | - Errors::notFound(class_basename($modelClass) . ' with id : ' . $data['id']); |
|
| 277 | + if ( ! $model) { |
|
| 278 | + Errors::notFound(class_basename($modelClass).' with id : '.$data['id']); |
|
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | /** |
@@ -331,7 +331,7 @@ discard block |
||
| 331 | 331 | * If the relation has no value then marke the relation data |
| 332 | 332 | * related to the model to be deleted. |
| 333 | 333 | */ |
| 334 | - if (!$value || !count($value)) { |
|
| 334 | + if ( ! $value || ! count($value)) { |
|
| 335 | 335 | $relations[$relation] = 'delete'; |
| 336 | 336 | } |
| 337 | 337 | } |
@@ -349,7 +349,7 @@ discard block |
||
| 349 | 349 | * Check if the relation is a collection. |
| 350 | 350 | */ |
| 351 | 351 | if (class_basename($model->$relation) == 'Collection') { |
| 352 | - if (!is_array($val)) { |
|
| 352 | + if ( ! is_array($val)) { |
|
| 353 | 353 | $relationModel = $relationBaseModel->lockForUpdate()->find($val); |
| 354 | 354 | } else { |
| 355 | 355 | /** |
@@ -362,8 +362,8 @@ discard block |
||
| 362 | 362 | /** |
| 363 | 363 | * If model doesn't exists. |
| 364 | 364 | */ |
| 365 | - if (!$relationModel) { |
|
| 366 | - Errors::notFound(class_basename($relationBaseModel) . ' with id : ' . $val['id']); |
|
| 365 | + if ( ! $relationModel) { |
|
| 366 | + Errors::notFound(class_basename($relationBaseModel).' with id : '.$val['id']); |
|
| 367 | 367 | } |
| 368 | 368 | |
| 369 | 369 | if (is_array($val)) { |
@@ -400,8 +400,8 @@ discard block |
||
| 400 | 400 | /** |
| 401 | 401 | * If model doesn't exists. |
| 402 | 402 | */ |
| 403 | - if (!$relationModel) { |
|
| 404 | - Errors::notFound(class_basename($relationBaseModel) . ' with id : ' . $value['id']); |
|
| 403 | + if ( ! $relationModel) { |
|
| 404 | + Errors::notFound(class_basename($relationBaseModel).' with id : '.$value['id']); |
|
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | foreach ($value as $relationAttribute => $relationValue) { |
@@ -569,11 +569,11 @@ discard block |
||
| 569 | 569 | |
| 570 | 570 | if ($key == 'and') { |
| 571 | 571 | $conditions = $this->constructConditions($value, $model); |
| 572 | - $conditionString .= str_replace('{op}', 'and', $conditions['conditionString']) . ' {op} '; |
|
| 572 | + $conditionString .= str_replace('{op}', 'and', $conditions['conditionString']).' {op} '; |
|
| 573 | 573 | $conditionValues = array_merge($conditionValues, $conditions['conditionValues']); |
| 574 | 574 | } elseif ($key == 'or') { |
| 575 | 575 | $conditions = $this->constructConditions($value, $model); |
| 576 | - $conditionString .= str_replace('{op}', 'or', $conditions['conditionString']) . ' {op} '; |
|
| 576 | + $conditionString .= str_replace('{op}', 'or', $conditions['conditionString']).' {op} '; |
|
| 577 | 577 | $conditionValues = array_merge($conditionValues, $conditions['conditionValues']); |
| 578 | 578 | } else { |
| 579 | 579 | if (is_array($value)) { |
@@ -589,38 +589,38 @@ discard block |
||
| 589 | 589 | } |
| 590 | 590 | |
| 591 | 591 | if (strtolower($operator) == 'between') { |
| 592 | - $conditionString .= $key . ' >= ? and '; |
|
| 592 | + $conditionString .= $key.' >= ? and '; |
|
| 593 | 593 | $conditionValues[] = $value1; |
| 594 | 594 | |
| 595 | - $conditionString .= $key . ' <= ? {op} '; |
|
| 595 | + $conditionString .= $key.' <= ? {op} '; |
|
| 596 | 596 | $conditionValues[] = $value2; |
| 597 | 597 | } elseif (strtolower($operator) == 'in') { |
| 598 | 598 | $conditionValues = array_merge($conditionValues, $value); |
| 599 | 599 | $inBindingsString = rtrim(str_repeat('?,', count($value)), ','); |
| 600 | - $conditionString .= $key . ' in (' . rtrim($inBindingsString, ',') . ') {op} '; |
|
| 600 | + $conditionString .= $key.' in ('.rtrim($inBindingsString, ',').') {op} '; |
|
| 601 | 601 | } elseif (strtolower($operator) == 'null') { |
| 602 | - $conditionString .= $key . ' is null {op} '; |
|
| 602 | + $conditionString .= $key.' is null {op} '; |
|
| 603 | 603 | } elseif (strtolower($operator) == 'not null') { |
| 604 | - $conditionString .= $key . ' is not null {op} '; |
|
| 604 | + $conditionString .= $key.' is not null {op} '; |
|
| 605 | 605 | } elseif (strtolower($operator) == 'has') { |
| 606 | 606 | $sql = $model->withTrashed()->withoutGlobalScopes()->has($key)->toSql(); |
| 607 | 607 | $bindings = $model->withTrashed()->withoutGlobalScopes()->has($key)->getBindings(); |
| 608 | 608 | if ($value) { |
| 609 | 609 | $conditions = $this->constructConditions($value, $model->$key()->getRelated()); |
| 610 | - $conditionString .= substr(substr($sql, strpos($sql, 'exists')), 0, -1) . ' and ' . $conditions['conditionString'] . ') {op} '; |
|
| 610 | + $conditionString .= substr(substr($sql, strpos($sql, 'exists')), 0, -1).' and '.$conditions['conditionString'].') {op} '; |
|
| 611 | 611 | $conditionValues = array_merge($conditionValues, $bindings); |
| 612 | 612 | $conditionValues = array_merge($conditionValues, $conditions['conditionValues']); |
| 613 | 613 | } else { |
| 614 | - $conditionString .= substr(substr($sql, strpos($sql, 'exists')), 0, -1) . ') {op} '; |
|
| 614 | + $conditionString .= substr(substr($sql, strpos($sql, 'exists')), 0, -1).') {op} '; |
|
| 615 | 615 | $conditionValues = array_merge($conditionValues, $bindings); |
| 616 | 616 | } |
| 617 | 617 | } else { |
| 618 | - $conditionString .= $key . ' ' . $operator . ' ? {op} '; |
|
| 618 | + $conditionString .= $key.' '.$operator.' ? {op} '; |
|
| 619 | 619 | $conditionValues[] = $value; |
| 620 | 620 | } |
| 621 | 621 | } |
| 622 | 622 | } |
| 623 | - $conditionString = '(' . rtrim($conditionString, '{op} ') . ')'; |
|
| 623 | + $conditionString = '('.rtrim($conditionString, '{op} ').')'; |
|
| 624 | 624 | return ['conditionString' => $conditionString, 'conditionValues' => $conditionValues]; |
| 625 | 625 | } |
| 626 | 626 | |
@@ -636,10 +636,10 @@ discard block |
||
| 636 | 636 | $value = $removeLast === false ? $value : substr($value, 0, $removeLast); |
| 637 | 637 | $path = explode('->', $value); |
| 638 | 638 | $field = array_shift($path); |
| 639 | - $result = sprintf('%s->\'$.%s\'', $field, collect($path)->map(function ($part) { |
|
| 640 | - return '"' . $part . '"'; |
|
| 639 | + $result = sprintf('%s->\'$.%s\'', $field, collect($path)->map(function($part) { |
|
| 640 | + return '"'.$part.'"'; |
|
| 641 | 641 | })->implode('.')); |
| 642 | 642 | |
| 643 | - return $removeLast === false ? $result : $result . ')'; |
|
| 643 | + return $removeLast === false ? $result : $result.')'; |
|
| 644 | 644 | } |
| 645 | 645 | } |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | { |
| 50 | 50 | $translatable = $this->repo->model->translatable ?? []; |
| 51 | 51 | $filters = $this->constructFilters($conditions); |
| 52 | - $sortBy = in_array($sortBy, $translatable) ? $sortBy . '->' . $this->session->get('locale') : $sortBy; |
|
| 52 | + $sortBy = in_array($sortBy, $translatable) ? $sortBy.'->'.$this->session->get('locale') : $sortBy; |
|
| 53 | 53 | |
| 54 | 54 | if ($trashed) { |
| 55 | 55 | return $this->deleted(['and' => $filters], $perPage ?? 15, $sortBy ?? 'created_at', $desc ?? true); |
@@ -217,18 +217,18 @@ discard block |
||
| 217 | 217 | /** |
| 218 | 218 | * Prepare key based on the the requested lang if it was translatable. |
| 219 | 219 | */ |
| 220 | - $key = in_array($key, $translatable) ? $key . '->' . ($this->session->get('locale') == 'all' ? 'en' : $this->session->get('locale')) : $key; |
|
| 220 | + $key = in_array($key, $translatable) ? $key.'->'.($this->session->get('locale') == 'all' ? 'en' : $this->session->get('locale')) : $key; |
|
| 221 | 221 | |
| 222 | 222 | /** |
| 223 | 223 | * Convert 0/1 or true/false to boolean in case of not foreign key. |
| 224 | 224 | */ |
| 225 | - if (filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) !== null && strpos($key, '_id') === false && !is_null($value)) { |
|
| 225 | + if (filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) !== null && strpos($key, '_id') === false && ! is_null($value)) { |
|
| 226 | 226 | $filters[$key] = filter_var($value, FILTER_VALIDATE_BOOLEAN); |
| 227 | 227 | |
| 228 | 228 | /** |
| 229 | 229 | * Use in operator in case of foreign and comma seperated values. |
| 230 | 230 | */ |
| 231 | - } elseif (!is_array($value) && strpos($key, '_id') && $value) { |
|
| 231 | + } elseif ( ! is_array($value) && strpos($key, '_id') && $value) { |
|
| 232 | 232 | $filters[$key] = [ |
| 233 | 233 | 'op' => 'in', |
| 234 | 234 | 'val' => explode(',', $value) |
@@ -252,11 +252,11 @@ discard block |
||
| 252 | 252 | * Default string filteration. |
| 253 | 253 | */ |
| 254 | 254 | } elseif ($value) { |
| 255 | - $key = 'LOWER(' . $key . ')'; |
|
| 255 | + $key = 'LOWER('.$key.')'; |
|
| 256 | 256 | $value = strtolower($value); |
| 257 | 257 | $filters[$key] = [ |
| 258 | 258 | 'op' => 'like', |
| 259 | - 'val' => '%' . $value . '%' |
|
| 259 | + 'val' => '%'.$value.'%' |
|
| 260 | 260 | ]; |
| 261 | 261 | } |
| 262 | 262 | } |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | $permissions = []; |
| 71 | 71 | $user = $this->repo->find(\Auth::id(), $relations); |
| 72 | 72 | foreach ($user->roles as $role) { |
| 73 | - $role->permissions->each(function ($permission) use (&$permissions) { |
|
| 73 | + $role->permissions->each(function($permission) use (&$permissions) { |
|
| 74 | 74 | $permissions[] = $permission; |
| 75 | 75 | }); |
| 76 | 76 | } |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | public function assignRoles($userId, $roleIds) |
| 134 | 134 | { |
| 135 | 135 | $user = false; |
| 136 | - \DB::transaction(function () use ($userId, $roleIds, &$user) { |
|
| 136 | + \DB::transaction(function() use ($userId, $roleIds, &$user) { |
|
| 137 | 137 | $user = $this->repo->find($userId); |
| 138 | 138 | $this->repo->detachRoles($user); |
| 139 | 139 | $this->repo->attachRoles($user, $roleIds); |
@@ -151,11 +151,11 @@ discard block |
||
| 151 | 151 | */ |
| 152 | 152 | public function login($email, $password) |
| 153 | 153 | { |
| 154 | - if (!$user = $this->repo->first(['email' => $email])) { |
|
| 154 | + if ( ! $user = $this->repo->first(['email' => $email])) { |
|
| 155 | 155 | \Errors::loginFailed(); |
| 156 | 156 | } elseif ($user->blocked) { |
| 157 | 157 | \Errors::userIsBlocked(); |
| 158 | - } elseif (!config('user.disable_confirm_email') && !$user->confirmed) { |
|
| 158 | + } elseif ( ! config('user.disable_confirm_email') && ! $user->confirmed) { |
|
| 159 | 159 | \Errors::emailNotConfirmed(); |
| 160 | 160 | } |
| 161 | 161 | |
@@ -174,11 +174,11 @@ discard block |
||
| 174 | 174 | $accessToken = $authCode ? Arr::get(\Socialite::driver($type)->getAccessTokenResponse($authCode), 'access_token') : $accessToken; |
| 175 | 175 | $user = \Socialite::driver($type)->userFromToken($accessToken)->user; |
| 176 | 176 | |
| 177 | - if (!Arr::has($user, 'email')) { |
|
| 177 | + if ( ! Arr::has($user, 'email')) { |
|
| 178 | 178 | \Errors::noSocialEmail(); |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | - if (!$this->repo->first(['email' => $user['email']]) && !$this->repo->deleted(['email' => $user['email']])->count()) { |
|
| 181 | + if ( ! $this->repo->first(['email' => $user['email']]) && ! $this->repo->deleted(['email' => $user['email']])->count()) { |
|
| 182 | 182 | $this->register(Arr::get($user, 'name'), $user['email'], '', true); |
| 183 | 183 | } |
| 184 | 184 | |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | |
| 203 | 203 | $user = $this->repo->save($data); |
| 204 | 204 | |
| 205 | - if (!$skipConfirmEmail && !config('user.disable_confirm_email')) { |
|
| 205 | + if ( ! $skipConfirmEmail && ! config('user.disable_confirm_email')) { |
|
| 206 | 206 | $this->sendConfirmationEmail($user->email); |
| 207 | 207 | } |
| 208 | 208 | |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | */ |
| 244 | 244 | public function sendReset($email) |
| 245 | 245 | { |
| 246 | - if (!$user = $this->repo->first(['email' => $email])) { |
|
| 246 | + if ( ! $user = $this->repo->first(['email' => $email])) { |
|
| 247 | 247 | \Errors::notFound('email'); |
| 248 | 248 | } |
| 249 | 249 | |
@@ -267,7 +267,7 @@ discard block |
||
| 267 | 267 | 'password' => $password, |
| 268 | 268 | 'password_confirmation' => $passwordConfirmation, |
| 269 | 269 | 'token' => $token |
| 270 | - ], function ($user, $password) { |
|
| 270 | + ], function($user, $password) { |
|
| 271 | 271 | $this->repo->save(['id' => $user->id, 'password' => $password]); |
| 272 | 272 | }); |
| 273 | 273 | |
@@ -300,7 +300,7 @@ discard block |
||
| 300 | 300 | public function changePassword($password, $oldPassword) |
| 301 | 301 | { |
| 302 | 302 | $user = \Auth::user(); |
| 303 | - if (!\Hash::check($oldPassword, $user->password)) { |
|
| 303 | + if ( ! \Hash::check($oldPassword, $user->password)) { |
|
| 304 | 304 | \Errors::invalidOldPassword(); |
| 305 | 305 | } |
| 306 | 306 | |
@@ -315,7 +315,7 @@ discard block |
||
| 315 | 315 | */ |
| 316 | 316 | public function confirmEmail($confirmationCode) |
| 317 | 317 | { |
| 318 | - if (!$user = $this->repo->first(['confirmation_code' => $confirmationCode])) { |
|
| 318 | + if ( ! $user = $this->repo->first(['confirmation_code' => $confirmationCode])) { |
|
| 319 | 319 | \Errors::invalidConfirmationCode(); |
| 320 | 320 | } |
| 321 | 321 | |