@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | use Illuminate\Database\Eloquent\Model; |
| 4 | 4 | use Illuminate\Database\Eloquent\SoftDeletes; |
| 5 | 5 | |
| 6 | -class Report extends Model{ |
|
| 6 | +class Report extends Model { |
|
| 7 | 7 | |
| 8 | 8 | use SoftDeletes; |
| 9 | 9 | protected $table = 'reports'; |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | protected $hidden = ['deleted_at']; |
| 12 | 12 | protected $guarded = ['id']; |
| 13 | 13 | protected $fillable = ['report_name', 'view_name']; |
| 14 | - public $searchable = ['report_name', 'view_name']; |
|
| 14 | + public $searchable = ['report_name', 'view_name']; |
|
| 15 | 15 | |
| 16 | 16 | public function getCreatedAtAttribute($value) |
| 17 | 17 | { |
@@ -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 | /** |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | */ |
| 251 | 251 | if ( ! $relationModel) |
| 252 | 252 | { |
| 253 | - \ErrorHandler::notFound(class_basename($relationBaseModel) . ' with id : ' . $val['id']); |
|
| 253 | + \ErrorHandler::notFound(class_basename($relationBaseModel).' with id : '.$val['id']); |
|
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | /** |
@@ -261,7 +261,7 @@ discard block |
||
| 261 | 261 | /** |
| 262 | 262 | * Prevent the sub relations or attributes not in the fillable. |
| 263 | 263 | */ |
| 264 | - if (gettype($val) !== 'object' && gettype($val) !== 'array' && array_search($attr, $relationModel->getFillable(), true) !== false) |
|
| 264 | + if (gettype($val) !== 'object' && gettype($val) !== 'array' && array_search($attr, $relationModel->getFillable(), true) !== false) |
|
| 265 | 265 | { |
| 266 | 266 | $relationModel->$attr = $val; |
| 267 | 267 | } |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | */ |
| 290 | 290 | if ( ! $relationModel) |
| 291 | 291 | { |
| 292 | - \ErrorHandler::notFound(class_basename($relationBaseModel) . ' with id : ' . $value['id']); |
|
| 292 | + \ErrorHandler::notFound(class_basename($relationBaseModel).' with id : '.$value['id']); |
|
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | /** |
@@ -426,11 +426,11 @@ discard block |
||
| 426 | 426 | { |
| 427 | 427 | if ($attribute == 'id') |
| 428 | 428 | { |
| 429 | - \DB::transaction(function () use ($value, $attribute, &$result, $saveLog) { |
|
| 429 | + \DB::transaction(function() use ($value, $attribute, &$result, $saveLog) { |
|
| 430 | 430 | $model = $this->model->lockForUpdate()->find($value); |
| 431 | 431 | if ( ! $model) |
| 432 | 432 | { |
| 433 | - \ErrorHandler::notFound(class_basename($this->model) . ' with id : ' . $value); |
|
| 433 | + \ErrorHandler::notFound(class_basename($this->model).' with id : '.$value); |
|
| 434 | 434 | } |
| 435 | 435 | |
| 436 | 436 | $model->delete(); |
@@ -439,8 +439,8 @@ discard block |
||
| 439 | 439 | } |
| 440 | 440 | else |
| 441 | 441 | { |
| 442 | - \DB::transaction(function () use ($value, $attribute, &$result, $saveLog) { |
|
| 443 | - call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function ($model){ |
|
| 442 | + \DB::transaction(function() use ($value, $attribute, &$result, $saveLog) { |
|
| 443 | + call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function($model) { |
|
| 444 | 444 | $model->delete(); |
| 445 | 445 | $saveLog ? \Logging::saveLog('delete', class_basename($this->model), $this->getModel(), $model->id, $model) : false; |
| 446 | 446 | }); |
@@ -477,7 +477,7 @@ discard block |
||
| 477 | 477 | { |
| 478 | 478 | $conditions = $this->constructConditions($conditions); |
| 479 | 479 | $sort = $desc ? 'desc' : 'asc'; |
| 480 | - return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->get($columns); |
|
| 480 | + return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->get($columns); |
|
| 481 | 481 | } |
| 482 | 482 | |
| 483 | 483 | /** |
@@ -508,21 +508,21 @@ discard block |
||
| 508 | 508 | { |
| 509 | 509 | if ($key == 'and') |
| 510 | 510 | { |
| 511 | - $conditionString .= str_replace('{op}', 'and', $this->constructConditions($value)['conditionString']) . ' {op} '; |
|
| 511 | + $conditionString .= str_replace('{op}', 'and', $this->constructConditions($value)['conditionString']).' {op} '; |
|
| 512 | 512 | $conditionValues = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']); |
| 513 | 513 | } |
| 514 | 514 | else if ($key == 'or') |
| 515 | 515 | { |
| 516 | - $conditionString .= str_replace('{op}', 'or', $this->constructConditions($value)['conditionString']) . ' {op} '; |
|
| 516 | + $conditionString .= str_replace('{op}', 'or', $this->constructConditions($value)['conditionString']).' {op} '; |
|
| 517 | 517 | $conditionValues = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']); |
| 518 | 518 | } |
| 519 | 519 | else |
| 520 | 520 | { |
| 521 | - $conditionString .= $key . '=? {op} '; |
|
| 521 | + $conditionString .= $key.'=? {op} '; |
|
| 522 | 522 | $conditionValues[] = $value; |
| 523 | 523 | } |
| 524 | 524 | } |
| 525 | - $conditionString = '(' . rtrim($conditionString, '{op} ') . ')'; |
|
| 525 | + $conditionString = '('.rtrim($conditionString, '{op} ').')'; |
|
| 526 | 526 | return ['conditionString' => $conditionString, 'conditionValues' => $conditionValues]; |
| 527 | 527 | } |
| 528 | 528 | |