12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php
- namespace App\Repositories\Criteria\Base;
- use App\Repositories\Models\Base\UserMessage;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Auth;
- use Prettus\Repository\Contracts\CriteriaInterface;
- use Prettus\Repository\Contracts\RepositoryInterface;
- class UserMessageCriteria implements CriteriaInterface
- {
- /**
- * @var \Illuminate\Http\Request
- */
- protected $request;
- public function __construct(Request $request)
- {
- $this->request = $request;
- }
- /**
- * @param $model
- * @param RepositoryInterface $repository
- *
- * @return mixed
- */
- public function apply($model, RepositoryInterface $repository)
- {
- if ($this->request->filled('name')) {
- $model = $model->where('name', 'like', '%' . $this->request->get('name') . '%');
- }
- if ($this->request->filled('is_read')) {
- $model = $model->where('is_read', '=', $this->request->get('is_read'));
- } else {
- $model = $model->where('is_read', '=', UserMessage::IS_READ_NO);
- }
- if ($this->request->filled('type')) {
- $model = $model->where('type', '=', $this->request->get('type'));
- }
- if ($this->request->filled('guard') || $this->request->header('guard')) {
- $guard = $this->request->get('guard', $this->request->header('guard'));
- $user = Auth::guard($guard)->user();
- $model = $model->where('user_id', $user->id)->where('user_type', get_class($user));
- } else {
- $user = login_admin();
- $model = $model->where('user_id', $user->id)->where('user_type', get_class($user));
- }
- $model = $model->orderByDesc('id');
- return $model;
- }
- }
|