123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- <?php
- namespace App\Repositories\Criteria\Note;
- use Illuminate\Http\Request;
- use Prettus\Repository\Contracts\CriteriaInterface;
- use Prettus\Repository\Contracts\RepositoryInterface;
- /**
- * Class CommentCriteria.
- *
- * @package namespace App\Repositories\Criteria\Note;
- */
- class CommentCriteria implements CriteriaInterface
- {
- 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 ($note_id = $this->request->get('note_id')) {
- $model = $model->where('note_id', '=', $note_id);
- }
- if (($parent_id = $this->request->get('parent_id', false)) !== false) {
- $model = $model->where('parent_id', '=', $parent_id);
- }
- if ($id = $this->request->get('id')) {
- $model = $model->where('id', '=', $id);
- }
- $model = $model->orderByDesc('is_answer')->orderByDesc('id');
- return $model;
- }
- }
|