Example of Local scopes in LaravelDaily/Laravel-Support-Ticketing

File app/Ticket.php (link to Github)
use Illuminate\Database\Eloquent\Model;
use Spatie\MediaLibrary\HasMedia;

class Ticket extends Model implements HasMedia
{
    //
    public function scopeFilterTickets($query)
    {
        $query->when(request()->input('priority'), function($query) {
                $query->whereHas('priority', function($query) {
                    $query->whereId(request()->input('priority'));
                });
            })
            ->when(request()->input('category'), function($query) {
                $query->whereHas('category', function($query) {
                    $query->whereId(request()->input('category'));
                });
            })
            ->when(request()->input('status'), function($query) {
                $query->whereHas('status', function($query) {
                    $query->whereId(request()->input('status'));
                });
            });
    }
    //
}
File app/Http/Controllers/Admin/TicketsController.php (link to Github)
use App\Http\Controllers\Controller;
use App\Ticket;
use Illuminate\Http\Request;

class TicketsController extends Controller
{
    public function index(Request $request)
    {
        if ($request->ajax()) {
            $query = Ticket::with(['status', 'priority', 'category', 'assigned_to_user', 'comments'])
                ->filterTickets($request)
                ->select(sprintf('%s.*', (new Ticket)->table));
                //
        }
        //
    }
    //
}

Additional resources on local scopes: