Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Sunshine And March Vibes (2025 Wallpapers Edition)

      May 16, 2025

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      May 16, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      May 16, 2025

      How To Prevent WordPress SQL Injection Attacks

      May 16, 2025

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025

      Bing Search APIs to be “decommissioned completely” as Microsoft urges developers to use its Azure agentic AI alternative

      May 16, 2025

      Microsoft might kill the Surface Laptop Studio as production is quietly halted

      May 16, 2025

      Minecraft licensing robbed us of this controversial NFL schedule release video

      May 16, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      The power of generators

      May 16, 2025
      Recent

      The power of generators

      May 16, 2025

      Simplify Factory Associations with Laravel’s UseFactory Attribute

      May 16, 2025

      This Week in Laravel: React Native, PhpStorm Junie, and more

      May 16, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025
      Recent

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025

      Bing Search APIs to be “decommissioned completely” as Microsoft urges developers to use its Azure agentic AI alternative

      May 16, 2025

      Microsoft might kill the Surface Laptop Studio as production is quietly halted

      May 16, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»Apply Dynamic Filters to Eloquent Models with the Filterable Package

    Apply Dynamic Filters to Eloquent Models with the Filterable Package

    April 25, 2024

    Filterable is a Laravel package by Jerome Thayananthajothy that enhances Laravel queries with adaptable, customizable filters and intelligent caching to improve both performance and functionality.

    The main features of this package include:

    Dynamic Filtering: Apply filters based on request parameters with ease.

    Caching: Improve performance by caching query results.

    User-specific Filtering: Easily implement filters that depend on the authenticated user.

    Custom Filter Methods: Extend the class to add your own filter methods.

    Defining Filter classes is at the center of this package, where you can create methods that can apply filtering to Eloquent queries. The package includes a make:filter Artisan command to generate a filter in your app’s AppFilters namespace. Here’s an example of a filter from the package’s README:

    namespace AppFilters;

    use FilterableFilter;
    use IlluminateDatabaseEloquentBuilder;

    class PostFilter extends Filter
    {
    protected array $filters = [‘status’, ‘category’];

    protected function status(string $value): Builder
    {
    return $this->builder->where(‘status’, $value);
    }

    protected function category(int $value): Builder
    {
    return $this->builder->where(‘category_id’, $value);
    }
    }

    Given a PostFilter, you can utilize this class in a controller with the Post model to filter models based on the HTTP query params:

    public function index(Request $request, PostFilter $filter)
    {
    // i.e., /posts?status=active&category_id=2
    $query = Post::filter($filter);

    $posts = $request->has(‘paginate’)
    ? $query->paginate($request->query(‘per_page’, 20))
    : $query->get();

    return response()->json($posts);
    }

    You can learn more about this package, get full installation instructions, and view the source code on GitHub.

    The post Apply Dynamic Filters to Eloquent Models with the Filterable Package appeared first on Laravel News.

    Join the Laravel Newsletter to get all the latest Laravel articles like this directly in your inbox.

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleMicrosoft Clarity Integration for Laravel
    Next Article Fixing 404 Responses for Versioned Images in Experience Edge

    Related Posts

    Security

    Nmap 7.96 Launches with Lightning-Fast DNS and 612 Scripts

    May 16, 2025
    Common Vulnerabilities and Exposures (CVEs)

    CVE-2025-2305 – Apache Linux Path Traversal Vulnerability

    May 16, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    CVE-2025-47770 – Apache HTTP Server Cross-Site Request Forgery

    Common Vulnerabilities and Exposures (CVEs)

    Development Release: AlmaLinux OS 9.6 Beta

    News & Updates

    Scale your relational database for SaaS, Part 2: Sharding and routing

    Databases

    CodeSOD: Not Exactly Gems

    News & Updates

    Highlights

    Google Spoofed in Sophisticated DKIM Replay Attack Exploiting Email Trust Mechanisms

    April 21, 2025

    Google Spoofed in Sophisticated DKIM Replay Attack Exploiting Email Trust Mechanisms

    What if an email in your inbox looked exactly like it came from Google—passed all authentication checks, had no spelling errors, came from a Google domain, and even discussed a subpoena involving your …
    Read more

    Published Date:
    Apr 22, 2025 (1 hour, 50 minutes ago)

    Vulnerabilities has been mentioned in this article.

    CVE-2025-33028

    CVE-2023-42442

    Supply Chain Attacks Becoming a Near-Daily Occurrence: Cyble Research

    August 20, 2024

    Step-By-Step Process Guide to Turning Off Google AI Overview in Google Search

    March 23, 2025

    I found a mini PC that can be a powerful Windows alternative – and it’s not a Mac

    April 30, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.