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
|
|
|
|
*/
|
|
|
|
class WhereCriteria implements CriteriaInterface
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var \Illuminate\Http\Request
|
|
|
|
*/
|
2018-08-27 00:40:04 +08:00
|
|
|
protected $request;
|
|
|
|
protected $where;
|
2017-12-05 00:34:01 +08:00
|
|
|
|
|
|
|
public function __construct($request, $where)
|
|
|
|
{
|
|
|
|
$this->request = $request;
|
|
|
|
$this->where = $where;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Apply criteria in query repository
|
|
|
|
*
|
2018-08-27 00:40:04 +08:00
|
|
|
* @param Builder|Model $model
|
|
|
|
* @param RepositoryInterface $repository
|
2017-12-05 00:34:01 +08:00
|
|
|
*
|
|
|
|
* @throws \Exception
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
|
|
|
* @return mixed
|
2017-12-05 00:34:01 +08:00
|
|
|
*/
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|