2017-12-05 00:34:01 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Repositories\Criteria;
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
use Prettus\Repository\Contracts\CriteriaInterface;
|
|
|
|
use Prettus\Repository\Contracts\RepositoryInterface;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class RequestCriteria
|
|
|
|
* @package Prettus\Repository\Criteria
|
|
|
|
*/
|
|
|
|
class WhereCriteria implements CriteriaInterface
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var \Illuminate\Http\Request
|
|
|
|
*/
|
|
|
|
protected $request, $where;
|
|
|
|
|
|
|
|
public function __construct($request, $where)
|
|
|
|
{
|
|
|
|
$this->request = $request;
|
|
|
|
$this->where = $where;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Apply criteria in query repository
|
|
|
|
*
|
|
|
|
* @param Builder|Model $model
|
2018-03-20 09:50:40 +08:00
|
|
|
* @param RepositoryInterface $repository
|
2017-12-05 00:34:01 +08:00
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
* @throws \Exception
|
|
|
|
*/
|
|
|
|
public function apply($model, RepositoryInterface $repository)
|
|
|
|
{
|
2018-03-20 09:50:40 +08:00
|
|
|
if ($this->where) {
|
2017-12-05 00:34:01 +08:00
|
|
|
$model = $model->where($this->where);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $model;
|
|
|
|
}
|
|
|
|
}
|