<?php namespace App\ModelFilters; use App\Models\Enums\ObjectApprovalStatus; use Carbon\Carbon; use EloquentFilter\ModelFilter; use Illuminate\Support\Facades\Auth; class ApprovalFilter extends ModelFilter { /** * Related Models that have ModelFilters as well as the method on the ModelFilter * As [relationMethod => [input_key1, input_key2]]. * * @var array */ public $relations = []; public function setup() { $tab = $this->query['tab'] ?? null; $this->where(function ($query) use ($tab) { return match ($tab) { 'wait_for_me' => $query->where("users", 'like', '%,'.Auth::id().',%')->where("status", ObjectApprovalStatus::DOING), 'approved' => $query, 'pr' => $query->where("created_at", Auth::id()), default => $query->where("created_at", Auth::id())->orWhere("users", 'like', '%,'.Auth::id().',%'), }; }); } }