@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | * |
| 41 | 41 | * @param array $relations |
| 42 | 42 | * @param string $sortBy |
| 43 | - * @param boolean $desc |
|
| 43 | + * @param integer $desc |
|
| 44 | 44 | * @param array $columns |
| 45 | 45 | * @return collection |
| 46 | 46 | */ |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | * @param integer $perPage |
| 61 | 61 | * @param array $relations |
| 62 | 62 | * @param string $sortBy |
| 63 | - * @param boolean $desc |
|
| 63 | + * @param integer $desc |
|
| 64 | 64 | * @param array $columns |
| 65 | 65 | * @return collection |
| 66 | 66 | */ |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | * @param integer $perPage |
| 80 | 80 | * @param array $relations |
| 81 | 81 | * @param string $sortBy |
| 82 | - * @param boolean $desc |
|
| 82 | + * @param integer $desc |
|
| 83 | 83 | * @param array $columns |
| 84 | 84 | * @return collection |
| 85 | 85 | */ |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | * @param integer $perPage |
| 101 | 101 | * @param array $relations |
| 102 | 102 | * @param string $sortBy |
| 103 | - * @param boolean $desc |
|
| 103 | + * @param integer $desc |
|
| 104 | 104 | * @param array $columns |
| 105 | 105 | * @return collection |
| 106 | 106 | */ |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | * @param array $conditions array of conditions |
| 180 | 180 | * @param array $relations |
| 181 | 181 | * @param string $sortBy |
| 182 | - * @param boolean $desc |
|
| 182 | + * @param integer $desc |
|
| 183 | 183 | * @param array $columns |
| 184 | 184 | * @return collection |
| 185 | 185 | */ |
@@ -214,7 +214,7 @@ discard block |
||
| 214 | 214 | * @param array $conditions array of conditions |
| 215 | 215 | * @param integer $perPage |
| 216 | 216 | * @param string $sortBy |
| 217 | - * @param boolean $desc |
|
| 217 | + * @param integer $desc |
|
| 218 | 218 | * @param array $columns |
| 219 | 219 | * @return collection |
| 220 | 220 | */ |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | public function search($query, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*')) |
| 68 | 68 | { |
| 69 | 69 | $page = \Request::get('page') ?? '1'; |
| 70 | - $cacheKey = 'search.' . $perPage . '.' . $query . '.' . $page; |
|
| 70 | + $cacheKey = 'search.'.$perPage.'.'.$query.'.'.$page; |
|
| 71 | 71 | return $this->cache->tags([$this->model])->rememberForever($cacheKey, function() use ($query, $perPage, $relations, $sortBy, $desc, $columns) { |
| 72 | 72 | return $this->repo->search($query, $perPage, $relations, $sortBy, $desc, $columns); |
| 73 | 73 | }); |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*')) |
| 87 | 87 | { |
| 88 | 88 | $page = \Request::get('page') ?? '1'; |
| 89 | - $cacheKey = 'paginate.' . $perPage . '.' . $page; |
|
| 89 | + $cacheKey = 'paginate.'.$perPage.'.'.$page; |
|
| 90 | 90 | return $this->cache->tags([$this->model])->rememberForever($cacheKey, function() use ($perPage, $relations, $sortBy, $desc, $columns) { |
| 91 | 91 | return $this->repo->paginate($perPage, $relations, $sortBy, $desc, $columns); |
| 92 | 92 | }); |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*')) |
| 108 | 108 | { |
| 109 | 109 | $page = \Request::get('page') ?? '1'; |
| 110 | - $cacheKey = 'paginateBy.' . $perPage . '.' . $page . '.' . serialize($conditions); |
|
| 110 | + $cacheKey = 'paginateBy.'.$perPage.'.'.$page.'.'.serialize($conditions); |
|
| 111 | 111 | return $this->cache->tags([$this->model])->rememberForever($cacheKey, function() use ($conditions, $perPage, $relations, $sortBy, $desc, $columns) { |
| 112 | 112 | return $this->repo->paginateBy($conditions, $perPage, $relations, $sortBy, $desc, $columns); |
| 113 | 113 | }); |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | */ |
| 167 | 167 | public function find($id, $relations = [], $columns = array('*')) |
| 168 | 168 | { |
| 169 | - $cacheKey = 'find.' . $id; |
|
| 169 | + $cacheKey = 'find.'.$id; |
|
| 170 | 170 | return $this->cache->tags([$this->model])->rememberForever($cacheKey, function() use ($id, $relations, $columns) { |
| 171 | 171 | return $this->repo->find($id, $relations, $columns); |
| 172 | 172 | }); |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | */ |
| 186 | 186 | public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*')) |
| 187 | 187 | { |
| 188 | - $cacheKey = 'findBy.' . serialize($conditions); |
|
| 188 | + $cacheKey = 'findBy.'.serialize($conditions); |
|
| 189 | 189 | return $this->cache->tags([$this->model])->rememberForever($cacheKey, function() use ($conditions, $relations, $sortBy, $desc, $columns) { |
| 190 | 190 | return $this->repo->findBy($conditions, $relations, $sortBy, $desc, $columns); |
| 191 | 191 | }); |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | */ |
| 203 | 203 | public function first($conditions, $relations = [], $columns = array('*')) |
| 204 | 204 | { |
| 205 | - $cacheKey = 'first.' . serialize($conditions); |
|
| 205 | + $cacheKey = 'first.'.serialize($conditions); |
|
| 206 | 206 | return $this->cache->tags([$this->model])->rememberForever($cacheKey, function() use ($conditions, $relations, $columns) { |
| 207 | 207 | return $this->repo->first($conditions, $relations, $columns); |
| 208 | 208 | }); |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | public function deleted($conditions, $perPage = 15, $sortBy = 'created_at', $desc = 1, $columns = array('*')) |
| 222 | 222 | { |
| 223 | 223 | $page = \Request::get('page') ?? '1'; |
| 224 | - $cacheKey = 'deleted.' . $perPage . '.' . $page . '.' . serialize($conditions); |
|
| 224 | + $cacheKey = 'deleted.'.$perPage.'.'.$page.'.'.serialize($conditions); |
|
| 225 | 225 | return $this->cache->tags([$this->model])->rememberForever($cacheKey, function() use ($conditions, $perPage, $sortBy, $desc, $columns) { |
| 226 | 226 | return $this->repo->deleted($conditions, $perPage, $sortBy, $desc, $columns); |
| 227 | 227 | }); |
@@ -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) |
@@ -433,7 +433,7 @@ discard block |
||
| 433 | 433 | } |
| 434 | 434 | else |
| 435 | 435 | { |
| 436 | - call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function ($model) use ($data, $saveLog){ |
|
| 436 | + call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function($model) use ($data, $saveLog){ |
|
| 437 | 437 | $model->update($data); |
| 438 | 438 | $saveLog ? \Logging::saveLog('update', class_basename($this->model), $this->getModel(), $model->id, $model) : false; |
| 439 | 439 | }); |
@@ -452,11 +452,11 @@ discard block |
||
| 452 | 452 | { |
| 453 | 453 | if ($attribute == 'id') |
| 454 | 454 | { |
| 455 | - \DB::transaction(function () use ($value, $attribute, &$result, $saveLog) { |
|
| 455 | + \DB::transaction(function() use ($value, $attribute, &$result, $saveLog) { |
|
| 456 | 456 | $model = $this->model->lockForUpdate()->find($value); |
| 457 | 457 | if ( ! $model) |
| 458 | 458 | { |
| 459 | - \ErrorHandler::notFound(class_basename($this->model) . ' with id : ' . $value); |
|
| 459 | + \ErrorHandler::notFound(class_basename($this->model).' with id : '.$value); |
|
| 460 | 460 | } |
| 461 | 461 | |
| 462 | 462 | $model->delete(); |
@@ -465,8 +465,8 @@ discard block |
||
| 465 | 465 | } |
| 466 | 466 | else |
| 467 | 467 | { |
| 468 | - \DB::transaction(function () use ($value, $attribute, &$result, $saveLog) { |
|
| 469 | - call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function ($model) use ($saveLog){ |
|
| 468 | + \DB::transaction(function() use ($value, $attribute, &$result, $saveLog) { |
|
| 469 | + call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function($model) use ($saveLog){ |
|
| 470 | 470 | $model->delete(); |
| 471 | 471 | $saveLog ? \Logging::saveLog('delete', class_basename($this->model), $this->getModel(), $model->id, $model) : false; |
| 472 | 472 | }); |
@@ -503,7 +503,7 @@ discard block |
||
| 503 | 503 | { |
| 504 | 504 | $conditions = $this->constructConditions($conditions, $this->model); |
| 505 | 505 | $sort = $desc ? 'desc' : 'asc'; |
| 506 | - return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->get($columns); |
|
| 506 | + return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->get($columns); |
|
| 507 | 507 | } |
| 508 | 508 | |
| 509 | 509 | /** |
@@ -543,7 +543,7 @@ discard block |
||
| 543 | 543 | $model->whereRaw($conditions['conditionString'], $conditions['conditionValues']); |
| 544 | 544 | } |
| 545 | 545 | |
| 546 | - return $model->orderBy($sortBy, $sort)->paginate($perPage, $columns);; |
|
| 546 | + return $model->orderBy($sortBy, $sort)->paginate($perPage, $columns); ; |
|
| 547 | 547 | } |
| 548 | 548 | |
| 549 | 549 | /** |
@@ -558,7 +558,7 @@ discard block |
||
| 558 | 558 | |
| 559 | 559 | if ( ! $model) |
| 560 | 560 | { |
| 561 | - \ErrorHandler::notFound(class_basename($this->model) . ' with id : ' . $id); |
|
| 561 | + \ErrorHandler::notFound(class_basename($this->model).' with id : '.$id); |
|
| 562 | 562 | } |
| 563 | 563 | |
| 564 | 564 | $model->restore(); |
@@ -578,13 +578,13 @@ discard block |
||
| 578 | 578 | if ($key == 'and') |
| 579 | 579 | { |
| 580 | 580 | $conditions = $this->constructConditions($value, $model); |
| 581 | - $conditionString .= str_replace('{op}', 'and', $conditions['conditionString']) . ' {op} '; |
|
| 581 | + $conditionString .= str_replace('{op}', 'and', $conditions['conditionString']).' {op} '; |
|
| 582 | 582 | $conditionValues = array_merge($conditionValues, $conditions['conditionValues']); |
| 583 | 583 | } |
| 584 | 584 | else if ($key == 'or') |
| 585 | 585 | { |
| 586 | 586 | $conditions = $this->constructConditions($value, $model); |
| 587 | - $conditionString .= str_replace('{op}', 'or', $conditions['conditionString']) . ' {op} '; |
|
| 587 | + $conditionString .= str_replace('{op}', 'or', $conditions['conditionString']).' {op} '; |
|
| 588 | 588 | $conditionValues = array_merge($conditionValues, $conditions['conditionValues']); |
| 589 | 589 | } |
| 590 | 590 | else |
@@ -609,41 +609,41 @@ discard block |
||
| 609 | 609 | |
| 610 | 610 | if (strtolower($operator) == 'between') |
| 611 | 611 | { |
| 612 | - $conditionString .= $key . ' >= ? and '; |
|
| 612 | + $conditionString .= $key.' >= ? and '; |
|
| 613 | 613 | $conditionValues[] = $value1; |
| 614 | 614 | |
| 615 | - $conditionString .= $key . ' <= ? {op} '; |
|
| 615 | + $conditionString .= $key.' <= ? {op} '; |
|
| 616 | 616 | $conditionValues[] = $value2; |
| 617 | 617 | } |
| 618 | 618 | elseif (strtolower($operator) == 'in') |
| 619 | 619 | { |
| 620 | 620 | $conditionValues = array_merge($conditionValues, $value); |
| 621 | 621 | $inBindingsString = rtrim(str_repeat('?,', count($value)), ','); |
| 622 | - $conditionString .= $key . ' in (' . rtrim($inBindingsString, ',') . ') {op} '; |
|
| 622 | + $conditionString .= $key.' in ('.rtrim($inBindingsString, ',').') {op} '; |
|
| 623 | 623 | } |
| 624 | 624 | elseif (strtolower($operator) == 'null') |
| 625 | 625 | { |
| 626 | - $conditionString .= $key . ' is null {op} '; |
|
| 626 | + $conditionString .= $key.' is null {op} '; |
|
| 627 | 627 | } |
| 628 | 628 | elseif (strtolower($operator) == 'not null') |
| 629 | 629 | { |
| 630 | - $conditionString .= $key . ' is not null {op} '; |
|
| 630 | + $conditionString .= $key.' is not null {op} '; |
|
| 631 | 631 | } |
| 632 | 632 | elseif (strtolower($operator) == 'has') |
| 633 | 633 | { |
| 634 | 634 | $sql = $model->withTrashed()->has($key)->toSql(); |
| 635 | 635 | $conditions = $this->constructConditions($value, $model->first()->$key); |
| 636 | - $conditionString .= rtrim(substr($sql, strpos($sql, 'exists')), ')') . ' and ' . $conditions['conditionString'] . ') {op} '; |
|
| 636 | + $conditionString .= rtrim(substr($sql, strpos($sql, 'exists')), ')').' and '.$conditions['conditionString'].') {op} '; |
|
| 637 | 637 | $conditionValues = array_merge($conditionValues, $conditions['conditionValues']); |
| 638 | 638 | } |
| 639 | 639 | else |
| 640 | 640 | { |
| 641 | - $conditionString .= $key . ' ' . $operator . ' ? {op} '; |
|
| 641 | + $conditionString .= $key.' '.$operator.' ? {op} '; |
|
| 642 | 642 | $conditionValues[] = $value; |
| 643 | 643 | } |
| 644 | 644 | } |
| 645 | 645 | } |
| 646 | - $conditionString = '(' . rtrim($conditionString, '{op} ') . ')'; |
|
| 646 | + $conditionString = '('.rtrim($conditionString, '{op} ').')'; |
|
| 647 | 647 | return ['conditionString' => $conditionString, 'conditionValues' => $conditionValues]; |
| 648 | 648 | } |
| 649 | 649 | |
@@ -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 | }); |