Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/Exceptions/InstanceOfException.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
use Exception;

/**
* @package Binaryk\LaravelRestify\Exceptions;
* @author Eduard Lupacescu <eduard.lupacescu@binarcode.com>
*/
class InstanceOfException extends Exception
{

}
30 changes: 15 additions & 15 deletions src/Services/Search/SearchService.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function search(RestifyRequest $request, Model $model)
}

/**
* Will prepare the eloquent array to return
* Will prepare the eloquent array to return.
*
* @return array
* @throws InstanceOfException
Expand All @@ -49,7 +49,7 @@ protected function prepare()
->prepareOrders($this->request->get('sort', ''))
->prepareRelations();
} else {
throw new InstanceOfException(__("Model is not an instance of :parent class", [
throw new InstanceOfException(__('Model is not an instance of :parent class', [
'parent' => RestifySearchable::class,
]));
}
Expand All @@ -63,7 +63,7 @@ protected function prepare()
}

/**
* Prepare eloquent exact fields
* Prepare eloquent exact fields.
*
* @param $fields
*
Expand All @@ -80,16 +80,16 @@ protected function prepareOperator($fields)
foreach ($values as $field => $value) {
$qualifiedField = $this->model->qualifyColumn($field);
switch ($key) {
case "gte":
case 'gte':
$this->builder->where($qualifiedField, '>=', $value);
break;
case "gt":
case 'gt':
$this->builder->where($qualifiedField, '>', $value);
break;
case "lte":
case 'lte':
$this->builder->where($qualifiedField, '<=', $value);
break;
case "lt":
case 'lt':
$this->builder->where($qualifiedField, '<', $value);
break;
}
Expand All @@ -101,15 +101,15 @@ protected function prepareOperator($fields)
}

/**
* Prepare eloquent exact fields
* Prepare eloquent exact fields.
*
* @param $fields
*
* @return $this
*/
protected function prepareMatchFields()
{
foreach($this->model::getMatchByFields() as $key => $type) {
foreach ($this->model::getMatchByFields() as $key => $type) {
if (! $this->request->has($key) && ! data_get($this->fixedInput, "match.$key")) {
continue;
}
Expand Down Expand Up @@ -149,7 +149,7 @@ protected function prepareMatchFields()
}

/**
* Prepare eloquent order by
* Prepare eloquent order by.
*
* @param $sort
*
Expand Down Expand Up @@ -177,7 +177,7 @@ protected function prepareOrders($sort)
}

/**
* Prepare relations
* Prepare relations.
*
* @return $this
*/
Expand Down Expand Up @@ -206,7 +206,7 @@ protected function prepareRelations()
}

/**
* Prepare search
* Prepare search.
*
* @param $search
* @return $this
Expand All @@ -221,23 +221,22 @@ protected function prepareSearchFields($search)
($connectionType != 'pgsql' || $search <= PHP_INT_MAX) &&
in_array($query->getModel()->getKeyName(), $this->model::getSearchableFields());


if ($canSearchPrimaryKey) {
$query->orWhere($query->getModel()->getQualifiedKeyName(), $search);
}

$likeOperator = $connectionType == 'pgsql' ? 'ilike' : 'like';

foreach ($this->model::getSearchableFields() as $column) {
$query->orWhere($this->model->qualifyColumn($column), $likeOperator, '%' . $search . '%');
$query->orWhere($this->model->qualifyColumn($column), $likeOperator, '%'.$search.'%');
}
});

return $this;
}

/**
* Set order
* Set order.
*
* @param $param
*
Expand All @@ -247,6 +246,7 @@ public function setOrder($param)
{
if ($param === 'random') {
$this->builder->inRandomOrder();

return $this;
}

Expand Down