1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- <?php
- namespace App\Repositories\Criteria\Base;
- use Illuminate\Http\Request;
- use Prettus\Repository\Contracts\CriteriaInterface;
- use Prettus\Repository\Contracts\RepositoryInterface;
- /**
- * Class MenuCriteria.
- *
- * @package namespace App\Repositories\Criteria\Base;
- */
- class MenuCriteria 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 (($status = $this->request->get('status', false)) !== false) {
- $model = $model->where('status', '=', $status);
- }
- // if ($language = $this->request->get('language')) {
- // $model = $model->where('language', '=', $language);
- // }
- $model = $model->orderByDesc('sort');
- return $model;
- }
- }
|