-
app/Models/Thread.php
Open in GitHub// In any Model, create methods scopeXxxxxx() // Then, you will be able to use them in Controller just like ->xxxxxx() final class Thread extends Model implements ReplyAble, SubscriptionAble, Feedable { // ... other Model methods public function scopeResolved(Builder $query): Builder { return $query->whereNotNull('solution_reply_id'); } public function scopeActive(Builder $query): Builder { return $query->has('repliesRelation'); } }
-
app/Http/Controllers/Forum/ThreadsController.php
Open in GitHub// We use ->resolved() and ->active() from that Scope class ThreadsController extends Controller { public function overview() { // ... other method code if ($filter === 'resolved') { $threads = Thread::feedQuery() ->resolved() ->paginate(20); } if ($filter === 'active') { $threads = Thread::feedQuery() ->active() ->paginate(20); } } }