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»Paginate Multiple Eloquent Models with the Union Paginator Package

    Paginate Multiple Eloquent Models with the Union Paginator Package

    December 20, 2024

    Paginate Multiple Eloquent Models with the Union Paginator Package

    The Laravel Union Paginator package by Austin White combines data from multiple Eloquent models into a single unified query using SQL unions. With this package, you can get “consistent pagination and customization across diverse data sources.”

    The UnionPaginator class is configured with models that extend the base Eloquent Model class. You have control over transforming each model’s records and calling paginate() on the UnionPaginator instance after configuring it:

    use AustinWUnionPaginatorUnionPaginator;
    
    // Define the models
    $paginator = UnionPaginator::for([User::class, Post::class]);
    
    // Apply transformations
    $paginator->transform(User::class, fn($record) => [
        'id' => $record->id,
        'name' => $record->name,
    ])->transform(Post::class, fn($record) => [
        'title' => $record->title,
        'created_at' => $record->created_at,
    ]);
    
    // Paginate the results
    $paginatedResults = $paginator->paginate(10);
    
    // Iterate through paginated items
    foreach ($paginatedResults->items() as $item) {
        // Process the paginated item
    }
    

    The Union Paginator package works with both Laravel v10 and Laravel v11. To get started with this package, check it out on GitHub at austinw/laravel-union-paginator.


    The post Paginate Multiple Eloquent Models with the Union Paginator 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 ArticleURI Parsing and Mutation in Laravel 11.35
    Next Article Securing Laravel Sessions with ID Regeneration

    Related Posts

    Security

    Nmap 7.96 Launches with Lightning-Fast DNS and 612 Scripts

    May 17, 2025
    Common Vulnerabilities and Exposures (CVEs)

    CVE-2024-47893 – VMware GPU Firmware Memory Disclosure

    May 17, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    Login with different Login ID’s for native mobile application using JMeter

    Development

    New Linux Rootkit PUMAKIT Uses Advanced Stealth Techniques to Evade Detection

    Development

    Samsung Health is adding these personalized wellness features – and they’re much needed

    News & Updates

    AB Download Manager – manage and organize downloading files

    Development
    GetResponse

    Highlights

    How Next.js Supercharges Load Times & Retains Customers

    February 24, 2025

    In today’s hyper-connected world, a website’s speed is no longer a mere technical detail —…

    How to correctly force a Vue component to re-render

    January 3, 2025

    In it to win it! WeLiveSecurity shortlisted for European Security Blogger Awards

    May 11, 2024

    How to Disable Overlay in Razer Cortex: Hide in-game Overlay

    February 13, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

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