@@ -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'] . ')'; |
|
636 | + $conditionString .= rtrim(substr($sql, strpos($sql, 'exists')), ')').' and '.$conditions['conditionString'].')'; |
|
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 |