-
composer.json
Open in GitHub{ "require": { "php": "^8.0", // "tucker-eric/eloquentfilter": "^2.2" }, }
-
app/Filters/ProjectFilter.php
Open in GitHubuse App\Models\Exception; use EloquentFilter\ModelFilter; class ProjectFilter extends ModelFilter { public function search($value) { return $this->where('title', 'like', '%' . $value . '%'); } public function hasOpenExceptions($value) { if (!$value) { return $this; } return $this->whereHas('exceptions', function ($query) { return $query->where('status', Exception::OPEN); }); } }
-
app/Http/Controllers/ProjectController.php
Open in GitHubuse App\Models\Project; class ProjectController extends Controller { public function index() { $projects = auth()->user() ->projects() ->select('id', 'title', 'total_exceptions') ->withCount('unreadExceptions') ->filter(request()->only('search')) ->latest('last_error_at') ->latest('created_at') ->paginate(); return inertia('Projects/Index', [ 'filters' => request()->only('search'), 'projects' => $projects, ]); } }