@@ -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(' . array_shift($conditionColumns) . ')'), 'LIKE', '%' . strtolower($query) . '%'); |
|
| 71 | + $q->where(\DB::raw('LOWER('.array_shift($conditionColumns).')'), '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(' . $column . ')'), 'LIKE', '%' . strtolower($query) . '%'); |
|
| 78 | + $q->orWhere(\DB::raw('LOWER('.$column.')'), '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(' . array_shift($subConditionColumns) . ')'), 'LIKE', '%' . strtolower($query) . '%'); |
|
| 111 | + $q->where(\DB::raw('LOWER('.array_shift($subConditionColumns).')'), '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(' . $subConditionColumn . ')'), 'LIKE', '%' . strtolower($query) . '%'); |
|
| 118 | + $q->orWhere(\DB::raw('LOWER('.$subConditionColumn.')'), '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 | |