phpvms/app/Repositories/Criteria/WhereCriteria.php

52 lines
1.0 KiB
PHP
Raw Normal View History

<?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;
/**
* Create a new Where search.
*
* @param $request
* @param $where
*/
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
*
* @throws \Exception
2018-08-27 00:40:04 +08:00
*
* @return mixed
*/
public function apply($model, RepositoryInterface $repository)
{
if ($this->where) {
$model = $model->where($this->where);
}
return $model;
}
}