Тёмный

Laravel: Change Two Symbols to Boost Eloquent Speed 

Laravel Daily
Подписаться 143 тыс.
Просмотров 85 тыс.
50% 1

A demo of a big e-shop simulation, where there are too many calculations are happening under the hood. Let's see why.
Related video:
New in Laravel 8: withSum/withMax/withAvg on Relationships • New in Laravel 8: with...
- - - - -
Support the channel by checking out our products:
- Try our Laravel QuickAdminPanel: bit.ly/quickad...
- Enroll in my Laravel courses: laraveldaily.t...
- Purchase my Livewire Kit: livewirekit.com
- Subscribe to my weekly newsletter: bit.ly/laravel-...

Хобби

Опубликовано:

 

22 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 192   
@L-A-O-S
@L-A-O-S 3 года назад
My day starts with laravel daily
@karlebh
@karlebh 3 года назад
I made this commitment some weeks ago to always watch the daily video and I have never regretted.
@tatendawilson3057
@tatendawilson3057 3 года назад
hahahah likewise
@secmazec
@secmazec 23 дня назад
My news start with laravel news
@user-rm4zo1mg5o
@user-rm4zo1mg5o 3 года назад
Finally someone explained the difference between call the relationship as property and method.
@jcc5018
@jcc5018 3 года назад
I was always confused about that too... Among other things
@AbedAbugozah
@AbedAbugozah 7 месяцев назад
it's too easy to degbug, as advise don't wait someone to explain in cases like this just test it
@ParidTvShow1
@ParidTvShow1 3 года назад
Laravel should reward you, you are increasing the numbers of Laravel Developers!
@LaravelDaily
@LaravelDaily 3 года назад
Laravel already rewarded me, I'm earning money from building the product on its ecosystem :)
@oleksiyraiu7190
@oleksiyraiu7190 3 года назад
@@LaravelDaily Nice!
@adebajooluwaseyi2124
@adebajooluwaseyi2124 3 года назад
laravel daily is turning to my first todo in the office
@secmazec
@secmazec 23 дня назад
Probably the most useful Laravel video of all time
@yasirtahirkheli74
@yasirtahirkheli74 Год назад
This small series on performance boosting an application using eloquent is a life-saver. Cant thank you enough mate..Such a to the point and professional approach. Long live😍
@ndeblauw
@ndeblauw 3 года назад
Amazing insight. Never seen it explained this clear and this obvious before. Keep on sharing!
@LaravelDaily
@LaravelDaily 3 года назад
Thanks for the kind words. That's partly what I'm trying to do on this channel: explain the things that I don't see explain elsewhere. There are a lot of articles on WHAT/HOW, but not enough on *totally practical* WHY.
@DonEjeh
@DonEjeh 3 года назад
​@@LaravelDaily if you can make a video on Persisting sessions across subdomains in Laravel.. share session/cookies across all subdomain and how to get them. also if the subdomain has it own session and to make the subdomain make you of the main domain session concurrently
@jcc5018
@jcc5018 3 года назад
@@LaravelDaily I feel like you need to get laravel to link to your videos in the documents or provide a mirrored docs with your additions, cause I get so confused reading the docs when they don't provide real example or why. I have been working on my project for a while and slowly making results, but I still don't understand most of it, and still forget things next time I need them cause I never really understood why I was doing it opposed to something else. It's kinda the same reason I failed calculus. Sure I can repeat a bunch of steps and get a result, but I never had any practical example to use it with. I sure wouldn't see some real world problem and think, I can use this calc equation here That's how I feel reading the docs or some videos. Such as explaining collection methods. The typical foo bar examples don't trigger my memory to use a certain thing when I may actually need it.
@abelenocrodriguez
@abelenocrodriguez 3 года назад
This is incredible, I imagined something like this but I wasn't sure about it, thanks for sharing this information.
@julienSibille
@julienSibille 3 года назад
This tip saved my project !
@Steviec63
@Steviec63 3 года назад
I had to watch this twice but now I've got it! Great lesson. Thank you.
@syahnurnizam1755
@syahnurnizam1755 3 года назад
it's worth noting that without the parentheses, you are returning a Laravel Collection of the related models. So the where() method was actually a Collection method, not an Eloquent Query Builder method. The Collection where() method is filtering out all the elements (Eloquent model objects) in the Collection loaded from the database which does not satify with the conditions in the where() method. Like what you had suggested, using the parentheses will return an Eloquent Query Builder, and the where() method is actually a Query Builder method, thus it actually performs a where query. Understanding this allows me makes better choice if I really want to load ALL the data from the db first then process the data or do I want to select the data from db specifically based on condition so I would get the actual data that I want from the db. Because sometimes, we do find ourselves in a situation where we need to get all the data first and then filter out the data into different categories. For that I think doing it in a single query is much better than multiple queries. Another tip is, if you manage to get the data that you want by filtering out a Collection of data, try to get the same data using a single query. The performance gain is worth the effort, even though if you have to use DB facade query builder. cheers!
@poplach
@poplach 3 года назад
Very good example, the confusing part for junior laravel developers is that 'where' and 'count' and other methods work BOTH on query builder and eloquent collection but logically it is two different things with same names. Just have to get used to work with query builder and its result - eloquent collection; and understand when query builder might become an eloquent collection, that's also important.
@marciopl2006
@marciopl2006 3 года назад
Olá .. mais um excelente vídeo. Durante a criação de aplicações, poucos desenvolvedores se preocupam em usar todo o potencial que um BD pode oferecer. Unido a uma boa ferramenta de ORM, as aplicações serão tão rápidas quando possível. Obrigado por compartilha seu conhecimento.
@andywong2244
@andywong2244 2 года назад
i used to do this all the time Povilas, now i know better thanks to you!
@bagussonarangga7283
@bagussonarangga7283 2 года назад
I have to send this to all my friend!! This is really awesome trick.
@pouriya2376
@pouriya2376 10 месяцев назад
Best laravel channel ever:)
@khafi22
@khafi22 3 года назад
The best laravel advice I had since long time 😁
@suryadeepbhujel22
@suryadeepbhujel22 3 года назад
Great logic , I was very much worried to my query in recent day, just I came back to my home and noticed your video , then tried to implement in my project , what great concept , Thankyou.
@deamoncomand
@deamoncomand 3 года назад
Dude. Your content is amazing and keeps me motivated to learn even more Laravel. Thank you so much!
@SahilKashyap64
@SahilKashyap64 3 года назад
I'd try the way you shared here. to reduce the model counts I use the 'toBase()' it basically doesn't prepare the model, downside is anything you have in model like a specific function won't work. Thanks for sharing , all of your videos are helping me make things better. :D
@prozacsf84
@prozacsf84 Год назад
You have withCount() for the initial query eager loading if you do need count
@Stoney_Eagle
@Stoney_Eagle 3 года назад
Amazing! Now I know why, I started caching to counter this behavior. Thanks!
@koldovalnya
@koldovalnya 2 года назад
I knew that problem will be with parentheses :D It's a common problem that many people do :) Your video forced me to install Laravel Debug Bar :D
@koldovalnya
@koldovalnya 2 года назад
Thank you, btw :P
@adityakadam2256
@adityakadam2256 3 года назад
Amazing tip. Such a small thing but makes a massive difference. Thanks for sharing it :)
@aomo5293
@aomo5293 2 года назад
Very good tips. Thank you
@bcmarcos03
@bcmarcos03 3 года назад
This is the kind of thing that is worth it! thank you for your time and your knowledge. Very well explained and very straight to the point!
@erichjordaan8864
@erichjordaan8864 3 года назад
Thanks for the amazing tip and explanation. Always look forward to your videos.
@FranzTech
@FranzTech 3 года назад
Hi 👋, that's really cool. To boost performance and enhance caching, you can create a new column in the product table "stock_left". Each time an order is created, you decrement stock_left. When the stock is added you increment it. By doing so you can easily get that data in a large listing without any performance issue.
@rokzabukovec4685
@rokzabukovec4685 3 года назад
But what can you do if two orderscome in in the same time? Which is possible with high traffic sites.
@Jurigag
@Jurigag 3 года назад
​@@rokzabukovec4685 just happens, then you have negative stock, nothing to do about this to be honest. One way to prevent it would be maybe redis or memcache so you can have real non-blocking atomic increment but you would still need to save it to database at some point. Other way is some messaging mechanism - and having only one worker reducing the stocks. This is overall a pretty problematic topic - like making sure that you will never sell something out of stock, and there is many examples of it not being solved, like shops cancelling orders because product is not available.
@paulbundy07
@paulbundy07 3 года назад
Thank you for daily useful videos.
@markusnf
@markusnf 3 года назад
So simple but such a great tip! Seeing it explained makes so much sense.
@mibrahim4245
@mibrahim4245 2 года назад
This guy is genius ! Respect
@KubilaTheFirst
@KubilaTheFirst 3 года назад
Thanks for the tips, you're making developers life easier.
@JamesAutoDude
@JamesAutoDude Год назад
Honestly this is what sets people apart from people who actually know laravel and people who don't
@codeology1
@codeology1 3 года назад
Please more please please make more,You are the tricks boss
@LaravelDaily
@LaravelDaily 3 года назад
Working on it :)
@vidhyaprakash85
@vidhyaprakash85 3 года назад
Thank you. I am about to implement same logic to show the remaining stocks.
@AbrarAhmad-mz8vl
@AbrarAhmad-mz8vl 3 года назад
Because Laravel collection and Query builder collection works same, almost same methods. It's hard for newbies to differentiate b/w
@martins-ecke
@martins-ecke 3 года назад
I just started replacing a whole bunch of "User::all()" calls ... 🙈🙈🙈 THANK YOU!
@abdelghaniabdou7578
@abdelghaniabdou7578 Год назад
this is very useful tip, thanks you for sharing that with us
@maxzak5310
@maxzak5310 3 года назад
i like to add a trigger to orders.products table to decrement products.stock with each row inserted , another trigger before update on Products to generate error if new stock value is negative .. this way u wont need t calculate remining product and avoid potential problems cuzed by race condition
@willzin-da-esfiha
@willzin-da-esfiha 9 месяцев назад
Wow, returning a query builder instance instead of a giant array is great
@chrismellor7027
@chrismellor7027 3 года назад
Excellent tip, will try to keep this in mind
@diegodig9
@diegodig9 2 года назад
Thank you very much for this, that's really important
@samirabboud2345
@samirabboud2345 3 года назад
This is very helpful and important tips
@warpig2786
@warpig2786 3 года назад
This reminds me a bit about pagination. When you do pagination are you making the query faster because you're asking to load a specific amount (i think max is 15) of resources as opposed to "all" ? Very useful trick. Thanks!!
@kingstalker
@kingstalker 2 года назад
Thank you for this is just gold
@jorgenash3452
@jorgenash3452 3 года назад
Dummm 🙉. This guy is really awesome. I follow you since 2018 in i guess i used to see all ur videos. Learned alot with u. Thankz 4 all
@isabelphillips451
@isabelphillips451 3 года назад
Wow!! I will have to take note of this and check my current project for this mistake 😅
@sensoeurn
@sensoeurn 3 года назад
Thank for sharing the tips
@UIT_GHOST
@UIT_GHOST 3 года назад
very nice, thanks so much for your sharing
@itsumairtech
@itsumairtech 3 года назад
Always helpful, Thanks for your great work
@newsall3049
@newsall3049 3 года назад
amazing, Small But Super Power Full Tips
@laithalenooz7082
@laithalenooz7082 3 года назад
make a small project on how to handle appointments (e.x. a clinic) and how can we implement Google Analytics in the dashboard please.
@shafqatalinawaz6218
@shafqatalinawaz6218 2 года назад
Great tip. Thank you so much for sharing:)
@helderneves91
@helderneves91 3 года назад
Really, really informative stuff! Thanks.
@AdityaPrasetyo19
@AdityaPrasetyo19 3 года назад
thank you very much. very helpful
@beatnu187
@beatnu187 3 года назад
Mind blowing! Thank you!
@nomankhan-st2dp
@nomankhan-st2dp 3 года назад
You are Great teacher, Thanks
@prozacsf84
@prozacsf84 Год назад
There is the opposite problem where one hardcoding queries and causes N+1 afterwards. If you want eager loading capable code you have to consider using getter or relationship attribute on intermediate level thus allow the upper level eager loading, speeding up drastically certain code
@nandkishor-gi8or
@nandkishor-gi8or 3 года назад
Amazingly important small useful tip not in mind while developing.
@GergelyCsermely
@GergelyCsermely 3 года назад
Thank You. Very good tip.
@davendranaraine3263
@davendranaraine3263 3 года назад
Thanks man! Your content is awesome
@MTD4dz
@MTD4dz 3 года назад
Amazing. I've been doing laravel at work for the past few months and didn't realise this. Thanks! I have a question though. If it's only a one to one relationship then does it matter if you use the () after the relationship since it would only ever get the one item?
@LaravelDaily
@LaravelDaily 3 года назад
Probably not.
@thineshnarasingam9328
@thineshnarasingam9328 8 месяцев назад
Thank you
@adebajooluwaseyi2124
@adebajooluwaseyi2124 3 года назад
there are too many people who don't know this, there are probably more who don't know than know, the query time effect won't be obvious if you don't have thousands of data, most junior developers don't work with such huge data, hence they never know
@LaravelDaily
@LaravelDaily 3 года назад
That's actually a great point: juniors don't write better code, partly because they don't work on projects large enough so they would feel the immediate difference/impact between bad code and good code. (goes on my Twitter)
@MrAvatarvb
@MrAvatarvb 3 года назад
شكرا جزيلا
@personalmail8083
@personalmail8083 3 года назад
Hi sir, How can be one to many relation on stock.. One product can have on stock...
@2am_yt
@2am_yt 3 года назад
Great Tip thank you!
@ambermonroe9363
@ambermonroe9363 3 года назад
thank you
@bulent2435
@bulent2435 3 года назад
That's amazing.
@schoolfaqs
@schoolfaqs 3 года назад
Great tip.
@brunomdsc
@brunomdsc 3 года назад
that is awesome. Thanks!
@mikaelDzp
@mikaelDzp 4 месяца назад
thankyou you have a new subs
@alessandrofuda965
@alessandrofuda965 3 года назад
Great! Very very usefull! Thanks
@rosselliot8971
@rosselliot8971 3 года назад
Pov, I think you should do another video on this topic. I was watching a Laracasts video not so long ago and Jeffrey Way mentioned this exact thing, the difference between the method being treated as a property versus a function, but I would have liked more detail.
@LaravelDaily
@LaravelDaily 3 года назад
I don't think it deserves more detail about the methods, unless you have some other practical example with it. I like to go very practical.
@victorkutenko9281
@victorkutenko9281 3 месяца назад
thanks!
@mohamednabih6036
@mohamednabih6036 3 года назад
amazing, thanks so much.
@enucar
@enucar 3 года назад
Another great video! Can you please upload a video of useful chrome addons you are using?
@LaravelDaily
@LaravelDaily 3 года назад
Only one: Fake Filler
@a-ezzat5677
@a-ezzat5677 3 года назад
thank you so much really, you are professional
@alishan5901
@alishan5901 Год назад
🔥👏🏻 thanks for sharing
@brianngetich007
@brianngetich007 3 года назад
Wow, thanks a lot.
@salimedia33
@salimedia33 3 года назад
Very Good Videos ;) Thank you.
@DonEjeh
@DonEjeh 3 года назад
whooooola Amazing tips... if you can make a video on Persisting sessions across subdomains in Laravel.. share session/cookies across all subdomain and how to get them. also if the subdomain has it own session and to make the subdomain make you of the main domain session concurrently
@z4ls7
@z4ls7 3 года назад
Can you repeat the same with like 1000 records and check how many queries does it generate ?
@ovidiufulea1883
@ovidiufulea1883 3 года назад
at 2:51 what do you have/use in the inspect section to get the queries, route, models. pls and thank you
@mohammedawni471
@mohammedawni471 3 года назад
Laravel Debugbar
@LEMPERBRO
@LEMPERBRO 6 месяцев назад
like eager load ?
@chlouis-girardot
@chlouis-girardot 3 года назад
Thanks Sir!
@rudyvaldano
@rudyvaldano 3 года назад
Thanks
@andresanez6558
@andresanez6558 3 года назад
Hey I have started learning Laravel because of your code review videos and now I'm following every video. I would like to know which plugin are you using for the type hinting when you call a method? Thanks in advance.
@LaravelDaily
@LaravelDaily 3 года назад
It's not a plugin, it's default phpstorm
@andresanez6558
@andresanez6558 3 года назад
@@LaravelDaily Thanks, I'm going to check it.
@anasnawaz3662
@anasnawaz3662 3 года назад
Wow good work. I have a question. How to manage guest users and Auth users in Restful APIs. All APIs makes secure. Nobody calls APIs using POST man and perform any action. if we are not apply auth middleware then all APIs secure less and anybody perform action. If we apply auth middleware then user must registered in my system and then use App. For example in App, user ABC login as a guest and place order using App (IOS,Android), after user ABC register in my system and properly logged in then how to manage orders and others data which is saved as a previous data when login as a guest?
@muhammadaftab9252
@muhammadaftab9252 Год назад
Thank you thank you thank you
@ervinselimovic4888
@ervinselimovic4888 3 года назад
Thanks!
@baadrqaaba9529
@baadrqaaba9529 3 года назад
All i can say is thank you .
@bishawjitmondol9284
@bishawjitmondol9284 3 месяца назад
Extraordinary
@salazar.focus8
@salazar.focus8 3 года назад
what does extension is it?
@MarlonLCosta
@MarlonLCosta Год назад
Awesome!
@aloha276
@aloha276 3 года назад
I just made a fresh laravel install and displayed the homepage (welcome.blade.php view) from routes.php no DB no controller, but the Debugbar package shows 17MB.. I wonder how did he drop it down till 5MB, i mean it should be at least 17MB because it seems like the Laravel booting alone consume 17MB of memory. Can anyone explain me how did he manage to do so ? Thanks
@jacebeleren1703
@jacebeleren1703 9 месяцев назад
Most likely you are loading css/js packages somewhere that total up to 17MB, he might have removed those.
@vaithiebby2198
@vaithiebby2198 3 года назад
Hi, i'm getting Call to undefined method Illuminate\Database\Eloquent\Builder::addEagerConstraints() error while calling like this, Booking::get()->load('getPackage','getServices'); in my booking model public function getServices() { return Services::whereIn('id',explode(',',$this->extra_service)); } i saved extra_service value in comma seprated string can anyone help me to solve this?
@MahmoudSaad4
@MahmoudSaad4 3 года назад
True
@omarzain3946
@omarzain3946 3 года назад
You are really amazing 👏❤
@icantchosemyname
@icantchosemyname 3 года назад
Thanks for the video. I have à question for anyone willing to help, In this kind of app, say we want to get the remaining stock of each product for each store (or location). For a database with 100 store, 5000 orders per store and 10 shared products. would it be a good idea to cache the remaining stocks or Just calculate it at every page refresh? I implémented à kind of caching but seeing the app performance in the video i might Just save the hassle and calculate the stocks. Ps: I know it may depend on stuffs like count of reads/writes but what do you guys think ? . Thanks
Далее
УГАДАЙ ЕДУ ПО ЭМОДЗИ! #shorts
00:57
Просмотров 81 тыс.
9 Tips for Shorter Laravel Code
10:16
Просмотров 61 тыс.
Optimizing Eloquent: Running Out Of Memory?
6:11
Просмотров 42 тыс.
Eloquent Performance: TOP 3 Mistakes Developers Make
7:59
Faster Eloquent: Avoid Accessors with Foreach
9:35
Просмотров 53 тыс.
Обзор Laravel Octane, Roadrunner, FrankenPHP
30:05
Top 5 Laravel "Bad Practices" (My Opinion)
10:32
Просмотров 20 тыс.
Why is Laravel NOT used in Big Development Projects?
11:53
Laravel: Create Public API with Cache and Rate Limits
12:18
Laravel Junior Code Review: Security and Consistency
17:29
Junior Code Review: Cleaning Up Laravel CRUD
14:54
Просмотров 68 тыс.
ПОДНЯЛСЯ И ОТОМСТИЛ
0:14
Просмотров 757 тыс.
Ma vie ❤️ #love
0:16
Просмотров 101 млн