@@ -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) |
@@ -435,7 +435,7 @@ discard block |
||
| 435 | 435 | } |
| 436 | 436 | else |
| 437 | 437 | { |
| 438 | - call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function ($model) use ($data, $saveLog){ |
|
| 438 | + call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function($model) use ($data, $saveLog){ |
|
| 439 | 439 | $model->update($data); |
| 440 | 440 | $saveLog ? \Logging::saveLog('update', class_basename($this->model), $this->getModel(), $model->id, $model) : false; |
| 441 | 441 | }); |
@@ -454,11 +454,11 @@ discard block |
||
| 454 | 454 | { |
| 455 | 455 | if ($attribute == 'id') |
| 456 | 456 | { |
| 457 | - \DB::transaction(function () use ($value, $attribute, &$result, $saveLog) { |
|
| 457 | + \DB::transaction(function() use ($value, $attribute, &$result, $saveLog) { |
|
| 458 | 458 | $model = $this->model->lockForUpdate()->find($value); |
| 459 | 459 | if ( ! $model) |
| 460 | 460 | { |
| 461 | - \ErrorHandler::notFound(class_basename($this->model) . ' with id : ' . $value); |
|
| 461 | + \ErrorHandler::notFound(class_basename($this->model).' with id : '.$value); |
|
| 462 | 462 | } |
| 463 | 463 | |
| 464 | 464 | $model->delete(); |
@@ -467,8 +467,8 @@ discard block |
||
| 467 | 467 | } |
| 468 | 468 | else |
| 469 | 469 | { |
| 470 | - \DB::transaction(function () use ($value, $attribute, &$result, $saveLog) { |
|
| 471 | - call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function ($model) use ($saveLog){ |
|
| 470 | + \DB::transaction(function() use ($value, $attribute, &$result, $saveLog) { |
|
| 471 | + call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function($model) use ($saveLog){ |
|
| 472 | 472 | $model->delete(); |
| 473 | 473 | $saveLog ? \Logging::saveLog('delete', class_basename($this->model), $this->getModel(), $model->id, $model) : false; |
| 474 | 474 | }); |
@@ -505,7 +505,7 @@ discard block |
||
| 505 | 505 | { |
| 506 | 506 | $conditions = $this->constructConditions($conditions, $this->model); |
| 507 | 507 | $sort = $desc ? 'desc' : 'asc'; |
| 508 | - return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->get($columns); |
|
| 508 | + return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->get($columns); |
|
| 509 | 509 | } |
| 510 | 510 | |
| 511 | 511 | /** |
@@ -545,7 +545,7 @@ discard block |
||
| 545 | 545 | $model->whereRaw($conditions['conditionString'], $conditions['conditionValues']); |
| 546 | 546 | } |
| 547 | 547 | |
| 548 | - return $model->orderBy($sortBy, $sort)->paginate($perPage, $columns);; |
|
| 548 | + return $model->orderBy($sortBy, $sort)->paginate($perPage, $columns); ; |
|
| 549 | 549 | } |
| 550 | 550 | |
| 551 | 551 | /** |
@@ -560,7 +560,7 @@ discard block |
||
| 560 | 560 | |
| 561 | 561 | if ( ! $model) |
| 562 | 562 | { |
| 563 | - \ErrorHandler::notFound(class_basename($this->model) . ' with id : ' . $id); |
|
| 563 | + \ErrorHandler::notFound(class_basename($this->model).' with id : '.$id); |
|
| 564 | 564 | } |
| 565 | 565 | |
| 566 | 566 | $model->restore(); |
@@ -580,13 +580,13 @@ discard block |
||
| 580 | 580 | if ($key == 'and') |
| 581 | 581 | { |
| 582 | 582 | $conditions = $this->constructConditions($value, $model); |
| 583 | - $conditionString .= str_replace('{op}', 'and', $conditions['conditionString']) . ' {op} '; |
|
| 583 | + $conditionString .= str_replace('{op}', 'and', $conditions['conditionString']).' {op} '; |
|
| 584 | 584 | $conditionValues = array_merge($conditionValues, $conditions['conditionValues']); |
| 585 | 585 | } |
| 586 | 586 | else if ($key == 'or') |
| 587 | 587 | { |
| 588 | 588 | $conditions = $this->constructConditions($value, $model); |
| 589 | - $conditionString .= str_replace('{op}', 'or', $conditions['conditionString']) . ' {op} '; |
|
| 589 | + $conditionString .= str_replace('{op}', 'or', $conditions['conditionString']).' {op} '; |
|
| 590 | 590 | $conditionValues = array_merge($conditionValues, $conditions['conditionValues']); |
| 591 | 591 | } |
| 592 | 592 | else |
@@ -611,41 +611,41 @@ discard block |
||
| 611 | 611 | |
| 612 | 612 | if (strtolower($operator) == 'between') |
| 613 | 613 | { |
| 614 | - $conditionString .= $key . ' >= ? and '; |
|
| 614 | + $conditionString .= $key.' >= ? and '; |
|
| 615 | 615 | $conditionValues[] = $value1; |
| 616 | 616 | |
| 617 | - $conditionString .= $key . ' <= ? {op} '; |
|
| 617 | + $conditionString .= $key.' <= ? {op} '; |
|
| 618 | 618 | $conditionValues[] = $value2; |
| 619 | 619 | } |
| 620 | 620 | elseif (strtolower($operator) == 'in') |
| 621 | 621 | { |
| 622 | 622 | $conditionValues = array_merge($conditionValues, $value); |
| 623 | 623 | $inBindingsString = rtrim(str_repeat('?,', count($value)), ','); |
| 624 | - $conditionString .= $key . ' in (' . rtrim($inBindingsString, ',') . ') {op} '; |
|
| 624 | + $conditionString .= $key.' in ('.rtrim($inBindingsString, ',').') {op} '; |
|
| 625 | 625 | } |
| 626 | 626 | elseif (strtolower($operator) == 'null') |
| 627 | 627 | { |
| 628 | - $conditionString .= $key . ' is null {op} '; |
|
| 628 | + $conditionString .= $key.' is null {op} '; |
|
| 629 | 629 | } |
| 630 | 630 | elseif (strtolower($operator) == 'not null') |
| 631 | 631 | { |
| 632 | - $conditionString .= $key . ' is not null {op} '; |
|
| 632 | + $conditionString .= $key.' is not null {op} '; |
|
| 633 | 633 | } |
| 634 | 634 | elseif (strtolower($operator) == 'has') |
| 635 | 635 | { |
| 636 | 636 | $sql = $model->withTrashed()->has($key)->toSql(); |
| 637 | 637 | $conditions = $this->constructConditions($value, $model->$key()->getRelated()); |
| 638 | - $conditionString .= rtrim(substr($sql, strpos($sql, 'exists')), ')') . ' and ' . $conditions['conditionString'] . ') {op} '; |
|
| 638 | + $conditionString .= rtrim(substr($sql, strpos($sql, 'exists')), ')').' and '.$conditions['conditionString'].') {op} '; |
|
| 639 | 639 | $conditionValues = array_merge($conditionValues, $conditions['conditionValues']); |
| 640 | 640 | } |
| 641 | 641 | else |
| 642 | 642 | { |
| 643 | - $conditionString .= $key . ' ' . $operator . ' ? {op} '; |
|
| 643 | + $conditionString .= $key.' '.$operator.' ? {op} '; |
|
| 644 | 644 | $conditionValues[] = $value; |
| 645 | 645 | } |
| 646 | 646 | } |
| 647 | 647 | } |
| 648 | - $conditionString = '(' . rtrim($conditionString, '{op} ') . ')'; |
|
| 648 | + $conditionString = '('.rtrim($conditionString, '{op} ').')'; |
|
| 649 | 649 | return ['conditionString' => $conditionString, 'conditionValues' => $conditionValues]; |
| 650 | 650 | } |
| 651 | 651 | |
@@ -432,8 +432,7 @@ discard block |
||
| 432 | 432 | $model = $this->model->lockForUpdate()->find($value); |
| 433 | 433 | $model ? $model->update($data) : 0; |
| 434 | 434 | $saveLog ? \Logging::saveLog('update', class_basename($this->model), $this->getModel(), $value, $model) : false; |
| 435 | - } |
|
| 436 | - else |
|
| 435 | + } else |
|
| 437 | 436 | { |
| 438 | 437 | call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function ($model) use ($data, $saveLog){ |
| 439 | 438 | $model->update($data); |
@@ -464,8 +463,7 @@ discard block |
||
| 464 | 463 | $model->delete(); |
| 465 | 464 | $saveLog ? \Logging::saveLog('delete', class_basename($this->model), $this->getModel(), $value, $model) : false; |
| 466 | 465 | }); |
| 467 | - } |
|
| 468 | - else |
|
| 466 | + } else |
|
| 469 | 467 | { |
| 470 | 468 | \DB::transaction(function () use ($value, $attribute, &$result, $saveLog) { |
| 471 | 469 | call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function ($model) use ($saveLog){ |
@@ -582,14 +580,12 @@ discard block |
||
| 582 | 580 | $conditions = $this->constructConditions($value, $model); |
| 583 | 581 | $conditionString .= str_replace('{op}', 'and', $conditions['conditionString']) . ' {op} '; |
| 584 | 582 | $conditionValues = array_merge($conditionValues, $conditions['conditionValues']); |
| 585 | - } |
|
| 586 | - else if ($key == 'or') |
|
| 583 | + } else if ($key == 'or') |
|
| 587 | 584 | { |
| 588 | 585 | $conditions = $this->constructConditions($value, $model); |
| 589 | 586 | $conditionString .= str_replace('{op}', 'or', $conditions['conditionString']) . ' {op} '; |
| 590 | 587 | $conditionValues = array_merge($conditionValues, $conditions['conditionValues']); |
| 591 | - } |
|
| 592 | - else |
|
| 588 | + } else |
|
| 593 | 589 | { |
| 594 | 590 | if (is_array($value)) |
| 595 | 591 | { |
@@ -598,13 +594,11 @@ discard block |
||
| 598 | 594 | { |
| 599 | 595 | $value1 = $value['val1']; |
| 600 | 596 | $value2 = $value['val2']; |
| 601 | - } |
|
| 602 | - else |
|
| 597 | + } else |
|
| 603 | 598 | { |
| 604 | 599 | $value = array_key_exists('val', $value) ? $value['val'] : ''; |
| 605 | 600 | } |
| 606 | - } |
|
| 607 | - else |
|
| 601 | + } else |
|
| 608 | 602 | { |
| 609 | 603 | $operator = '='; |
| 610 | 604 | } |
@@ -616,29 +610,24 @@ discard block |
||
| 616 | 610 | |
| 617 | 611 | $conditionString .= $key . ' <= ? {op} '; |
| 618 | 612 | $conditionValues[] = $value2; |
| 619 | - } |
|
| 620 | - elseif (strtolower($operator) == 'in') |
|
| 613 | + } elseif (strtolower($operator) == 'in') |
|
| 621 | 614 | { |
| 622 | 615 | $conditionValues = array_merge($conditionValues, $value); |
| 623 | 616 | $inBindingsString = rtrim(str_repeat('?,', count($value)), ','); |
| 624 | 617 | $conditionString .= $key . ' in (' . rtrim($inBindingsString, ',') . ') {op} '; |
| 625 | - } |
|
| 626 | - elseif (strtolower($operator) == 'null') |
|
| 618 | + } elseif (strtolower($operator) == 'null') |
|
| 627 | 619 | { |
| 628 | 620 | $conditionString .= $key . ' is null {op} '; |
| 629 | - } |
|
| 630 | - elseif (strtolower($operator) == 'not null') |
|
| 621 | + } elseif (strtolower($operator) == 'not null') |
|
| 631 | 622 | { |
| 632 | 623 | $conditionString .= $key . ' is not null {op} '; |
| 633 | - } |
|
| 634 | - elseif (strtolower($operator) == 'has') |
|
| 624 | + } elseif (strtolower($operator) == 'has') |
|
| 635 | 625 | { |
| 636 | 626 | $sql = $model->withTrashed()->has($key)->toSql(); |
| 637 | 627 | $conditions = $this->constructConditions($value, $model->$key()->getRelated()); |
| 638 | 628 | $conditionString .= rtrim(substr($sql, strpos($sql, 'exists')), ')') . ' and ' . $conditions['conditionString'] . ') {op} '; |
| 639 | 629 | $conditionValues = array_merge($conditionValues, $conditions['conditionValues']); |
| 640 | - } |
|
| 641 | - else |
|
| 630 | + } else |
|
| 642 | 631 | { |
| 643 | 632 | $conditionString .= $key . ' ' . $operator . ' ? {op} '; |
| 644 | 633 | $conditionValues[] = $value; |