Skip to content

Commit

Permalink
Update Queryable.php
Browse files Browse the repository at this point in the history
  • Loading branch information
arabnewscms authored Aug 23, 2023
1 parent 7e3f03d commit 5f61795
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/Base/Traits/Queryable.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@

trait Queryable {

/**
* replace_entity
* to check if use Spatie QueryBuilder Package
* https://github.com/spatie/laravel-query-builder
* @return object
*/
protected function replace_entity(){

return $this->spatieQueryBuilder?
\Spatie\QueryBuilder\QueryBuilder::for($this->entity) : new $this->entity;

}

/**
* master of query method
* @return query methods
Expand Down Expand Up @@ -85,7 +98,7 @@ public function afterRestore($entity):void {}
* @return entity query
*/
public function appendQuery() {
$query = $this->query(new $this->entity)->orderBy(request('orderBy', 'id'), request('sort', 'desc'));
$query = $this->query($this->replace_entity())->orderBy(request('orderBy', 'id'), request('sort', 'desc'));
if (request('limit') > 0) {
$query = $query->limit('limit', request('limit'));
}
Expand All @@ -96,7 +109,7 @@ public function appendQuery() {
* @return entity query
*/
public function appendShowQuery() {
return $this->beforeShow(new $this->entity)->orderBy(request('orderBy', 'id'), request('sort', 'desc'));
return $this->beforeShow($this->replace_entity())->orderBy(request('orderBy', 'id'), request('sort', 'desc'));
}

}

0 comments on commit 5f61795

Please sign in to comment.