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

      Sunshine And March Vibes (2025 Wallpapers Edition)

      May 12, 2025

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

      May 12, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      May 12, 2025

      How To Prevent WordPress SQL Injection Attacks

      May 12, 2025

      Microsoft aims to be “carbon negative” by 2030, with 3 million carbon removal credits in its backyard of Washington

      May 12, 2025

      Sam Altman doesn’t want his son to have an AI “bestie” — as Microsoft plans to turn Copilot into an AI friend and companion

      May 12, 2025

      ChatGPT downplays AI’s threat to humanity despite an apparent “99.999999% probability” of inevitable doom

      May 12, 2025

      Surface Pro 12-inch vs. iPad Air M3: Which should you choose?

      May 12, 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

      A customizable and accessible web component

      May 12, 2025
      Recent

      A customizable and accessible web component

      May 12, 2025

      How Agile Helps You Improve Your Agility

      May 12, 2025

      Laravel Seeder Generator

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

      Microsoft aims to be “carbon negative” by 2030, with 3 million carbon removal credits in its backyard of Washington

      May 12, 2025
      Recent

      Microsoft aims to be “carbon negative” by 2030, with 3 million carbon removal credits in its backyard of Washington

      May 12, 2025

      Sam Altman doesn’t want his son to have an AI “bestie” — as Microsoft plans to turn Copilot into an AI friend and companion

      May 12, 2025

      ChatGPT downplays AI’s threat to humanity despite an apparent “99.999999% probability” of inevitable doom

      May 12, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»Use a Closure with updateOrInsert() in Laravel 11.10

    Use a Closure with updateOrInsert() in Laravel 11.10

    June 5, 2024

    This week, the Laravel team released v11.10, with the ability to pass a callback to updateOrInsert, support for soft-deleted models with explicit route model binding, and more.

    Allow Passing a Callback to updateOrInsert()

    Mark Eriksson contributed the ability to pass a callback as the second argument to the updateOrInsert() query builder method. Within the callback, the boolean $exists variable is passed so you can write logic to update specific columns based on whether the record exists or not:

    DB::table(‘users’)->updateOrInsert(
    [‘user_id’ => $user_id],
    function ($exists) use ($data) {
    if ($exists) {
    return [
    ‘name’ => $data[‘name’],
    ’email’ => $data[’email’],
    ];
    }

    return [
    ‘name’ => $data[‘name’],
    ’email’ => $data[’email’],
    ‘optional_column’ => $data[‘foobar’],
    ];
    }
    );

    See Pull Request #51566 for full implementation details.

    Support Soft-deleted Models When Using Explicit Route Model Binding

    Graham Bradley added support for soft-deleted models when using explicit route model binding:

    This PR allows the resolution of soft-deleted models when using Laravel’s explicit route-model binding feature.

    It allows developers to use explicit route-model binding without having to customise the resolution logic when dealing with soft-deleted models. To do so it uses the same withTrashed() method as implicit binding.

    // Before
    Route::get(‘/users/{user}’, …);
    Route::bind(‘user’, function (string $value) {
    return User::where(‘id’, $value)->withTrashed()->firstOrFail();
    });

    // After
    Route::get(‘/users/{user}’, …)->withTrashed();
    Route::model(‘user’, User::class);

    See Pull Request #51651 for full implementation details.

    Allow Setting Resend API Key in Mailer Config

    @riasvdv contributed setting the Resend API key directly in the mailer config instead of just the services config. See Pull Request #51618 for more details.

    Release notes

    You can see the complete list of new features and updates below and the diff between 11.9.0 and 11.10.0 on GitHub. The following release notes are directly from the changelog:

    v11.10.0

    [11.x] Fix typo in filename by @Henridv in https://github.com/laravel/framework/pull/51643

    [11.x] Add Vite auto refresh to error page by @riasvdv in https://github.com/laravel/framework/pull/51635

    [11.x] Add test for join_paths by @imanghafoori1 in https://github.com/laravel/framework/pull/51621

    [11.x] Preload base options for missing config files by @jasonmccreary in https://github.com/laravel/framework/pull/51619

    [11.x] Add option to disable merging of base configuration by @taka-oyama in https://github.com/laravel/framework/pull/51579

    [11.x] Allow callback to be passed to updateOrInsert() to pass different $values if the record already exists by @Markshall in https://github.com/laravel/framework/pull/51566

    [11.x] Fix join_paths issue with segment ‘0’ by @imanghafoori1 in https://github.com/laravel/framework/pull/51649

    [11.x] Remove extra double quote in the error page by @nicolus in https://github.com/laravel/framework/pull/51670

    [11.x] Add tests to improve test coverage for HtmlString by @saMahmoudzadeh in https://github.com/laravel/framework/pull/51666

    [11.x] Add tests to improve test coverage for Arr::whereNotNull by @saMahmoudzadeh in https://github.com/laravel/framework/pull/51661

    [11.x] Add tests for FileSystem class by @imanghafoori1 in https://github.com/laravel/framework/pull/51654

    [11.x] Update OptimizeClearCommand.php by @nathanpurcell in https://github.com/laravel/framework/pull/51667

    [11.x] Support soft deleted models when using explicit route model binding by @gbradley in https://github.com/laravel/framework/pull/51651

    [11.x] Add tests for Arr::divide by @saMahmoudzadeh in https://github.com/laravel/framework/pull/51673

    [11.x] Prune should be a flag option by @riasvdv in https://github.com/laravel/framework/pull/51694

    [11.x] Avoid using Laravel new error page if app.debug changes to true at runtime by @crynobone in https://github.com/laravel/framework/pull/51705

    The post Use a Closure with updateOrInsert() in Laravel 11.10 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 ArticleJeffrey’s Larabits: An Anchor Within an Anchor?
    Next Article Cultivating a Performance Oriented Culture

    Related Posts

    Security

    Nmap 7.96 Launches with Lightning-Fast DNS and 612 Scripts

    May 13, 2025
    Common Vulnerabilities and Exposures (CVEs)

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

    May 13, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    Navigating Salesforce Record Types: A Beginner’s Guide

    Development
    Conditional Context Management Made Easy with Laravel’s Context Facade

    Conditional Context Management Made Easy with Laravel’s Context Facade

    Development

    Monster Hunter Wilds Showcase reveals new and returning monsters, cosmetic customization options, Photo Mode, Open Beta Test details, and more

    News & Updates

    Niche product design

    Web Development

    Highlights

    Operation FishMedley

    April 10, 2025

    ESET researchers detail a global espionage operation by FishMonger, the APT group run by I‑SOON…

    CVE-2024-13322 – WordPress Ads Pro Plugin SQL Injection Vulnerability

    May 2, 2025

    PeriodWave: A Novel Universal Waveform Generation Model

    August 20, 2024

    Lit.js: Building Fast, Lightweight, and Scalable Web Components

    May 5, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

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