diff --git a/app/Classes/General/Eloquent/AbstractGetRecord.php b/app/Classes/General/Eloquent/AbstractGetRecord.php index e2972eb0..f927d818 100644 --- a/app/Classes/General/Eloquent/AbstractGetRecord.php +++ b/app/Classes/General/Eloquent/AbstractGetRecord.php @@ -12,8 +12,6 @@ abstract class AbstractGetRecord /** @var array */ private const DECORATION_FILTERS = ['per_page', 'order_by']; - private const JOIN_FILTERS = ['joins']; - /** @var Collection */ private $filters; @@ -22,7 +20,7 @@ abstract class AbstractGetRecord * @return Collection */ private function getQueryFilters(){ - return $this->filters->except(array_merge(self::DECORATION_FILTERS, self::JOIN_FILTERS)); + return $this->filters->except(self::DECORATION_FILTERS); } /** @@ -32,10 +30,6 @@ abstract class AbstractGetRecord return $this->filters->only(self::DECORATION_FILTERS); } - public function getJoinFilters(){ - return $this->filters->only(self::JOIN_FILTERS); - } - /** * @param null|string $json * @return array @@ -49,13 +43,7 @@ abstract class AbstractGetRecord */ private function applyFiltersToQuery(): Builder { - $table = $this->getRepository()->getModel()->getTable(); - $a = $this->getQueryFilters()->toArray(); - $r=[]; - - array_walk($a, function ($v, $k) use ($table, &$r) { $r[$table.".".$k]=$v; }); - - return (new ApplyFiltersToQuery())->execute($this->getRepository(), $r); + return (new ApplyFiltersToQuery())->execute($this->getRepository(), $this->getQueryFilters()->toArray()); } /** @@ -79,4 +67,4 @@ abstract class AbstractGetRecord */ abstract function getResults(Builder $query); -} +} \ No newline at end of file diff --git a/app/Classes/General/Eloquent/AbstractListRecord.php b/app/Classes/General/Eloquent/AbstractListRecord.php index 830dad3c..01e66c29 100644 --- a/app/Classes/General/Eloquent/AbstractListRecord.php +++ b/app/Classes/General/Eloquent/AbstractListRecord.php @@ -6,7 +6,6 @@ namespace App\Classes\General\Eloquent; use App\Classes\Exceptions\MalformedRequestException; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\QueryException; -use Illuminate\Support\Facades\Schema; abstract class AbstractListRecord extends AbstractGetRecord { @@ -34,36 +33,10 @@ abstract class AbstractListRecord extends AbstractGetRecord * @return mixed */ public function getResults(Builder $query) { - - $filters = $this->getJoinFilters(); - $table = $query->getModel()->getTable(); - $selects = []; - - $selects[] = $table.".*,"; - - if($filters->has('joins')){ - - foreach($filters->get('joins') as $join){ - $join_table = $join->table; - $columns = Schema::getColumnListing($join_table); - - $r=[]; - array_walk($columns, function ($v, $k) use ($join_table, &$r) { $r[] = $join_table.".".$v." ".$join_table."_".$v; }); - $selects[] = implode(",",$r); - - $query = $query->join($join->table, function($q) use($join, $query) { - $q->on($query->getModel()->getTable().'.id', '=', $join->table.'.owner_id'); - }); - }; - - $query = $query->selectRaw(implode("",$selects)); - } - $filters = $this->getDecorationFilters(); if($filters->has('order_by')){ - $orderByTable = (strpos($filters->get('order_by')->column,".")===false) ? $query->getModel()->getTable()."." : ""; - $query = $query->orderBy($orderByTable.$filters->get('order_by')->column, $filters->get('order_by')->DESC ? 'DESC': 'ASC'); + $query = $query->orderBy($filters->get('order_by')->column, $filters->get('order_by')->DESC ? 'DESC': 'ASC'); } return $filters->has('per_page') ? $query->paginate($filters->get('per_page')) : $query->get();