123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- namespace App\Repositories\Criteria\User;
- use Illuminate\Http\Request;
- use Prettus\Repository\Contracts\CriteriaInterface;
- use Prettus\Repository\Contracts\RepositoryInterface;
- /**
- * Class StudentCriteria.
- *
- * @package namespace App\Repositories\Criteria\User\Student;
- */
- class StudentCriteria implements CriteriaInterface
- {
- /**
- * Apply criteria in query repository
- *
- * @param string $model
- * @param RepositoryInterface $repository
- *
- * @return mixed
- */
- public function __construct(Request $request = null)
- {
- if (is_null($request)) {
- $this->request = \request();
- } else {
- $this->request = $request;
- }
- }
- /**
- * Apply criteria in query repository
- *
- * @param string $model
- * @param RepositoryInterface $repository
- *
- * @return mixed
- */
- public function apply($model, RepositoryInterface $repository)
- {
- if ($turename = $this->request->get('turename')) {
- $model = $model->where('turename', 'like', "%{$turename}%");
- }
- if ($account = $this->request->get('account')) {
- $model = $model->where('account', 'like', "%{$account}%");
- }
- if ($period = $this->request->get('period')) {
- $model = $model->where('period', 'like', $period);
- }
- $model = $model->orderByDesc('id');
- return $model;
- }
- }
|