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»Dynamic Cache, Database, and Mail Builders in Laravel 11.31

    Dynamic Cache, Database, and Mail Builders in Laravel 11.31

    November 15, 2024

    Dynamic Cache, Database, and Mail Builders in Laravel 11.31

    The Laravel team released v11.31, which includes dynamic cache/db/mail builders, a cache token repository, a URL::forceHttps() convenience method, and more.

    Cache Token Repository

    Andrew Brown contributed a cache token repository as an alternative way to store password reset tokens:

    This PR proposes a new CacheTokenRepository which will allow the password reset tokens to be handled via cache. IMO cache is a perfect storage medium because it can be more ephemeral, just like the password reset tokens.

    To enable this new CacheTokenRepository, adjust your config/auth.php like so:

    'passwords' => [
    
        //new cache driver
        'customers' => [
            'driver'   => 'cache',
            'store'    => 'passwords',
            'provider' => 'customers',
            'expire'   => 60,
            'throttle' => 60,
        ],
    
       //default old database driver
        'users'     => [
            'provider' => 'users',
            'table'    =>'password_reset_tokens',
            'expire'   => 60,
            'throttle' => 60,
        ],
    ],
    

    See Pull Request #53428 for details on the implementation.

    Dynamically Build Mailers On-Demand

    Steve Bauman contributed the ability to dynamically build a mailer and send it using the Mail::build() method. This allows developers to create mailers based on a given configuration instead of being hard-coded in the config files:

    use IlluminateSupportFacadesMail;
    
    $mailer = Mail::build([
        'transport' => 'smtp',
        'host' => '127.0.0.1',
        'port' => 587,
        'encryption' => 'tls',
        'username' => 'usr',
        'password' => 'pwd',
        'timeout' => 5,
    ]);
    
    $mailer->send($mailable);
    

    See Pull Request #53411 for discussion and implementation details.

    Add DB::build() Method

    Similar to the Mail::build() method, Steve Bauman contributed DB::build() to dynamically create new DB connections that are not defined in your configuration file:

    use IlluminateSupportFacadesDB;
    
    $sqlite = DB::build([
        'driver' => 'sqlite',
        'database' => ':memory:',
    ]);
    
    $mysql = DB::build([
        'driver' => 'mysql',
        'database' => 'forge',
        'username' => 'root',
        'password' => 'secret',
    ]);
    
    $pgsql = DB::build([
        'driver' => 'pgsql',
        // ...
    ]);
    
    $sqlsrv = DB::build([
        'driver' => 'sqlsrv',
        // ...
    ]);
    

    See Pull Request #53464 for details.

    Add Cache::build() to Create On-demand Cache Repositories

    Steve Bauman contributed the ability to dynamically build Cache repositories on-demand using the Cache::build() method. Similar to the DB and Mailer dynamic build method, you can create cache repositories not defined in your configuration file:

    use IlluminateSupportFacadesCache;
    
    $apc = Cache::build([
        'driver' => 'apc',
    ]);
    
    $array = Cache::build([
        'driver' => 'array',
        'serialize' => false,
    ]);
    
    $database = Cache::build([
        'driver' => 'database',
        'table' => 'cache',
        'connection' => null,
        'lock_connection' => null,
    ]);
    
    $file = Cache::build([
        'driver' => 'file',
        'path' => storage_path('framework/cache/data'),
    ]); 
    

    See Pull Request #53454 for implementation details.

    Batch and Chain onQueue() Method Accepts Backed Enums

    Philip Iezzi contributed the ability to use a backed enumeration with the onQueue() method of a Bus chain:

    // Before
    Bus::chain($jobs)
        ->onQueue(QueueName::long->value)->dispatch();
    
    // After
    Bus::chain($jobs)
        ->onQueue(QueueName::long)->dispatch();
    

    See Pull Request #53359 for implementation details.

    Add Application removeDeferredServices() Method

    Ollie Read contributed the removeDeferredServices() application method to remove a deferred service from the application container.

    // Before
    $deferredServices = $app->getDeferredServices();
    
    unset($deferredServices['auth.password'], $deferredServices['auth.password.broker']);
    
    $app->setDeferredServices($deferredServices);
    
    // After
    $app->removeDeferredServices(['auth.password', 'auth.password.broker']);
    

    This use-case isn’t a common one that you’ll need, but this method compliments to get and set methods of deferred services nicely. See Pull Request #53362 for details.

    Ability to Append and Prepend Middleware Priority from the Application Builder

    Ollie Read contributed another low-level change to append and prepend middleware priority to the application builder, allowing access to add middleware after/before methods on the kernel:

    return Application::configure(basePath: dirname(__DIR__))
        ->withRouting(
            web: __DIR__.'/../routes/web.php',
            commands: __DIR__.'/../routes/console.php',
            health: '/up',
        )
        ->withMiddleware(function (Middleware $middleware) {
            $middleware->appendToPriorityList(
        [
            IlluminateCookieMiddlewareEncryptCookies::class,
            IlluminateContractsAuthMiddlewareAuthenticatesRequests::class,
        ],
        IlluminateRoutingMiddlewareValidateSignature::class
    );
    
    $middleware->prependToPriorityList(
        [
            IlluminateCookieMiddlewareEncryptCookies::class,
            IlluminateContractsAuthMiddlewareAuthenticatesRequests::class,
        ],
        IlluminateRoutingMiddlewareValidateSignature::class
    );
        })
        ->withExceptions(function (Exceptions $exceptions) {
            //
        })->create();
    

    See Pull Request #53326 for further details.

    Add forceHttps() Method to Enforce HTTPs Scheme for URLs

    Dasun Tharanga contributed the forceHttps() method, which simplifies enforcing HTTPs for URLs requiring such. The method accepts a boolean, making it easy to force HTTPs for a given set of environments:

    URL::forceHttps(
        $this->app->isProduction()
    );
    
    URL::forceHttps(
        $this->app->environment('staging', 'production')
    );
    

    See Pull Request #53381 for implementation details.

    Release notes

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

    v11.31.0

    • [11.x] Refactor: return Command::FAILURE by @fernandokbs in https://github.com/laravel/framework/pull/53354
    • Allow the Batch and Chain onQueue method to accept Backed Enums by @onlime in https://github.com/laravel/framework/pull/53359
    • Add transaction generics by @MatusBoa in https://github.com/laravel/framework/pull/53357
    • Add laravel default exception blade files to view:cache by @SamuelWei in https://github.com/laravel/framework/pull/53353
    • [11.x] Added useCascadeTruncate method for PostgresGrammar by @korkoshko in https://github.com/laravel/framework/pull/53343
    • Add Application::removeDeferredServices method by @ollieread in https://github.com/laravel/framework/pull/53362
    • Add the ability to append and prepend middleware priority from the application builder by @ollieread in https://github.com/laravel/framework/pull/53326
    • Fix typo in Translator code comment by @caendesilva in https://github.com/laravel/framework/pull/53366
    • [11.x] Handle HtmlString constructed with a null by @sperelson in https://github.com/laravel/framework/pull/53367
    • [11.x] Add URL::forceHttps() to enforce HTTPS scheme for URLs by @dasundev in https://github.com/laravel/framework/pull/53381
    • [11.x] Refactor and add remaining test cases for the DatabaseUuidFailedJobProviderTest class by @kevinb1989 in https://github.com/laravel/framework/pull/53408
    • [11.X] Postgres Aurora failover – DetectsLostConnections by @vifer in https://github.com/laravel/framework/pull/53404
    • whereFullText case consistency by @parth391 in https://github.com/laravel/framework/pull/53395
    • [11.x] Add HasFactory trait to make:model generation command using --all options by @adel007gh in https://github.com/laravel/framework/pull/53391
    • Introduce support for popping items from a stackable context item by @denjaland in https://github.com/laravel/framework/pull/53403
    • [11.x] Test Improvements by @crynobone in https://github.com/laravel/framework/pull/53414
    • [11.x] Add ability to dynamically build mailers on-demand using Mail::build by @stevebauman in https://github.com/laravel/framework/pull/53411
    • [11.x] Refactor and add remaining test cases for the DatabaseFailedJobProviderTest class by @kevinb1989 in https://github.com/laravel/framework/pull/53409
    • [11.x] Fix error event listener in Vite prefetching by @jnoordsij in https://github.com/laravel/framework/pull/53439
    • [11.x] Ensure datetime cache durations account for script execution time by @timacdonald in https://github.com/laravel/framework/pull/53431
    • [11.x] Fix fluent syntax for HasManyThrough when combining HasMany followed by HasOne by @jnoordsij in https://github.com/laravel/framework/pull/53335
    • Correct parameter type of Collection::diffKeys() and Collection::diffKeysUsing() by @AJenbo in https://github.com/laravel/framework/pull/53441
    • Correct parameter type of Collection::intersectByKeys() by @AJenbo in https://github.com/laravel/framework/pull/53444
    • Fix schema foreign ID support for tables with non-standard primary key by @willrowe in https://github.com/laravel/framework/pull/53442
    • [11.x] Cache token repository by @browner12 in https://github.com/laravel/framework/pull/53428
    • Fix validation message when there is a parameter with escaped dot “.” by @mdmahbubhelal in https://github.com/laravel/framework/pull/53416
    • [11.x] add optional prefix for cache key by @browner12 in https://github.com/laravel/framework/pull/53448
    • [11.x] Do not overwrite existing link header(s) in AddLinkHeadersForPreloadedAssets middleware by @jnoordsij in https://github.com/laravel/framework/pull/53463
    • [11.x] use assertTrue and assertFalse method, instead of using assertE… by @iamyusuf in https://github.com/laravel/framework/pull/53453
    • [11.x] Add DB::build method by @stevebauman in https://github.com/laravel/framework/pull/53464
    • [11.x] Add ability to dynamically build cache repositories on-demand using Cache::build by @stevebauman in https://github.com/laravel/framework/pull/53454
    • [11.x] Skip the number of connections transacting while testing to run callbacks by @tonysm in https://github.com/laravel/framework/pull/53377

    The post Dynamic Cache, Database, and Mail Builders in Laravel 11.31 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 Article20 MySQL Functions Examples from Laravel Projects
    Next Article 8 Digital Healthcare Trends For 2025

    Related Posts

    Security

    Nmap 7.96 Launches with Lightning-Fast DNS and 612 Scripts

    May 16, 2025
    Common Vulnerabilities and Exposures (CVEs)

    CVE-2025-47916 – Invision Community Themeeditor Remote Code Execution

    May 16, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    PlanRAG: A Plan-then-Retrieval Augmented Generation for Generative Large Language Models as Decision Makers

    Development

    OpenAI’s Sam Altman says AGI is becoming a “less useful term” with o1 — “astonishing cognitive capabilities” predicted before 2026

    Development

    How MongoDB Scales CoPilot AI’s Humanized Sales Interactions

    Databases

    PydanticAI: Advancing Generative AI Agent Development through Intelligent Framework Design

    Machine Learning

    Highlights

    Bleach: Brave Souls is now finally available on Xbox One

    June 28, 2024

    Bleach: Brave Souls, a free-to-play 3D action game that has captured many people’s love and…

    Chalk – terminal string styling

    December 8, 2024

    CVE-2025-27532 – “ctrlX OS Web Application Backup & Restore Authentication Bypass”

    April 30, 2025

    Building an AI-Powered FAQ Chatbot with Livewire & PrismPHP

    March 18, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

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