Vigyata.AI
Is this your channel?

New in Laravel 11 - The Once Method

6.3K views· 205 likes· 2:33· Mar 14, 2024

🛍️ Products Mentioned (3)

Here, we will be looking at the new once method in the Laravel 11. === Offer === GET 30% DISCOUNT ON ALL PLANS OF CLOUDWAYS HOSTING FOR 3 MONTHS https://unified.cloudways.com/signup?id=1029148&coupon=CW30FOR3 === Important Links === Fonts, extensions I use, and Support Laratips links: https://bit.ly/m/laratips === Video Related Links === === Other Videos === What's New In Laravel 9 https://youtu.be/qAzrZUG_9Z0 New In Laravel Playlist https://www.youtube.com/playlist?list=PL2DahmvUpeuu4UVWrcxlvVkMiI0SeS2OZ Laravel Package Development Playlist https://www.youtube.com/playlist?list=PL2DahmvUpeuu8HkpbNT-cKernolVdqZq_ Password Validation In Laravel with at least one Letters, Numbers, Upper and Lowercase or Symbols: https://youtu.be/f-g3P9imPZs Multiple Apis With ForwardsCalls Trait And Code Refactoring Tip - Laravel Hidden Feature: https://youtu.be/vzgNm86ezWE Laravel Chunking - You Might Be Doing This Wrong - Problem and Solution: https://youtu.be/aQCHmB4Uh0Q Laravel Tip - Properly Get Data Between Two Dates https://youtu.be/bJkEBTg1NGA Get Data From Multiple Databases In One Project | Laravel Tip https://youtu.be/KJAXLf78QPs === Attribution === Boy waving hand Video by VideoPlasty .com (https://pixabay.com/users/videoplasty-19751245/?utm_source=link-attribution&utm_medium=referral&utm_campaign=video&utm_content=80696) from Pixabay #laravel #php #laraveltip #laratips

About This Video

Laravel 11 is released, and in this video I’m talking about one of those small-but-super-useful features: the new `once()` method. I jump into a fresh Laravel project and show a simple example where I’m fetching the first user from the database. The problem is pretty common—if you call the same method from multiple places, you can easily end up running the exact same query multiple times. I enable query logging so you can literally see the duplicate query happening. Then I wrap the database call in `once()` by passing a closure, and that’s where the magic happens: no matter how many times I call that method, the database only gets hit once and the same result is reused. I really like this feature because it’s clean and it solves a real performance issue without extra boilerplate. After that, I also show a basic “manual” version of the same idea inside a class by caching the user in a property—so you understand what `once()` is doing conceptually. That’s it—quick, practical, and something I’m definitely going to use in many parts of my apps.

Frequently Asked Questions

🎬 More from Laratips