Faster Eloquent: Avoid Accessors with Foreach

  Рет қаралды 52,023

Laravel Daily

Laravel Daily

2 жыл бұрын

In this video, step-by-step we will optimize a page loading from 30+ seconds to 0.2 seconds, by avoiding a foreach loop with Eloquent Attributes.
Spatie Ray: spatie.be/products/ray
My 20 Laravel Eloquent Tips and Tricks: laravel-news.com/eloquent-tip...
- - - - -
Support the channel by checking out our products:
- Enroll in my Laravel courses: laraveldaily.teachable.com
- Try our Laravel QuickAdminPanel: bit.ly/quickadminpanel
- Purchase my Livewire Kit: livewirekit.com
- View Laravel Code Examples: laravelexamples.com
- Subscribe to my weekly newsletter: bit.ly/laravel-newsletter

Пікірлер: 69
@gillesashley9314
@gillesashley9314 Жыл бұрын
I believe this is by far the best laravel channel on KZfaq. Correct me if I'm wrong.
@BsiennKhan
@BsiennKhan 2 жыл бұрын
All of this spesific talk was music for my ears. I love tips on performance tuning, not only performance wise, it also helps you to be a better architect or engineer by following patterns AND improving cognative skills for future projects.
@unarmedwombat
@unarmedwombat 2 жыл бұрын
Possibly the single most useful tip I've seen this year. Thanks Povilas.
@Tooltrocity
@Tooltrocity 2 жыл бұрын
This is a great video, I love learning performance stuff like this. It's the nuts and bolts of a tool that people don't talk about often enough. Please make more videos like this!
@LeonelViera
@LeonelViera 2 жыл бұрын
Nice that you elaborate your thinking process
@jacquesmatike9289
@jacquesmatike9289 2 жыл бұрын
That's a huge optimization ! Thanks !!
@irvingviveros9314
@irvingviveros9314 2 жыл бұрын
New video = instant like! Thank you!
@abrpp
@abrpp 2 жыл бұрын
Always on point. Thank you!
@jamzykimani
@jamzykimani 10 ай бұрын
Awesome video👏👏 this plus the laravel-news article feels like a level up for me... So much actionable knowledge!!!
@obikwelukyrian6848
@obikwelukyrian6848 2 жыл бұрын
Watching your videos has made me an optimization freak tbh. And I'm not complaining 😊
@natenatters
@natenatters 2 жыл бұрын
Nice! Also, like you said at the end about caching, sometimes thats the best solution. You can use the existing logic and set an identity column inside of the User updating model event, then you bypass the need for an accessor.
@edsontomas8344
@edsontomas8344 Жыл бұрын
Keep dropping them gems. Thank you
@rafa.alcantara
@rafa.alcantara 2 жыл бұрын
Povilas GOOD JOB, getting better day after day, Thanks for your incredible amount of work!
@leydergananbueno5466
@leydergananbueno5466 2 жыл бұрын
Su canal es el mejor, he aprendido mucho de usted ¡muchas gracias! buen contenido
@devendergupta_official
@devendergupta_official 2 жыл бұрын
A very good lesson!
@ChangeYourLifeForever
@ChangeYourLifeForever 2 жыл бұрын
WOOW very intersting , we need more of those videos plz ( explain for us the eager VS normal ) loading data
@sachinvishwakarma290
@sachinvishwakarma290 2 жыл бұрын
Great and very helpful all your laravel video thanks 👍
@mikaelDzp
@mikaelDzp Ай бұрын
thank you! you deserve more views !
@ahanafi-id
@ahanafi-id 2 жыл бұрын
Great Video, thanks
@mohammadrezaarab7890
@mohammadrezaarab7890 Жыл бұрын
It was really helpful. thanks
@alexandrelima5886
@alexandrelima5886 2 жыл бұрын
Great approach! Thx
@demeja16
@demeja16 2 жыл бұрын
It is so cool, thank you for this video!:)
@intipontt7490
@intipontt7490 2 жыл бұрын
I'm sure there's a perfectly reasonable sql query that returns the same results. This is a perfect example of when NOT to use Eloquent.
@Khalyomede
@Khalyomede 2 жыл бұрын
I completely agree with you. I recently found out when using "with('relation')", Eloquent will not perform an inner or left join, it will make a second "select ... where parent_relation in (all ids of parent_relation)", which for me was counter intuitive at first, but in the end to be able to have such a powerful chainable language you need to make some tradeoffs I guess. It still does the job pretty well to have a readable code!
@idonnow2
@idonnow2 2 жыл бұрын
My first thought was to make a view in the DB lmao
@iamriwash7943
@iamriwash7943 2 жыл бұрын
finally i got what i looking for ( thanks)😊
@koldovalnya
@koldovalnya 2 жыл бұрын
Thanks 4 tutorial
@MrJoboski
@MrJoboski Жыл бұрын
Amazing!
@darkmode404
@darkmode404 2 жыл бұрын
Thank you!
@f00n168
@f00n168 2 жыл бұрын
Thank you 🙏🏻
@martinfeldman7340
@martinfeldman7340 Жыл бұрын
How can I add this video to some permanent list ? This is beyond excellent. Thank you so much Povilas!
@technical157
@technical157 2 жыл бұрын
very interesting. thx
@devMoemen
@devMoemen Жыл бұрын
very good thanks
@Shez-dc3fn
@Shez-dc3fn 2 жыл бұрын
whats baffling me is he does select id from users but in attr he uses $this->name which i assume is an attr of that table.. :/ this name will always be null/empty since its not selected
@07Weka
@07Weka 2 жыл бұрын
He discussed and solved that in the video :/
@kkamarada4
@kkamarada4 2 жыл бұрын
Nice work o/
@TimvandenBelt
@TimvandenBelt 2 жыл бұрын
Once again, a great and educational video! Thanks! However, a small suggestion if you wish to push performance and be more strict with how the app deals with variables (less unexpected behaviour): use identical comparison (===) where possible. I noticed that for several comparisons where it should always be a comparison between two integers, a lossy equation (==) is used.
@p30mehrdad
@p30mehrdad 2 жыл бұрын
Thanks
@ricko13
@ricko13 2 жыл бұрын
nuostabus, plojimai!
@SandorHorvathZ
@SandorHorvathZ 2 жыл бұрын
Thank you so much for this video. Fantastic example how Laravel devs abuse Models nowdays.
@shahsawoodshinwari
@shahsawoodshinwari 5 ай бұрын
When I have to choose between a method on eloquent and an accessor, i check if there is any query launched to db, if yes, then it is definetly not an accessor as accessors are loaded on model load, while methods don't.
@mikegodz
@mikegodz 2 жыл бұрын
Great video! Sometimes there's no reason not to do what the DB is designed to do. On the other hand, there are situation like the following: suppose you have a Posts/Comments project, and you want to show all the comments of a user, but visually divided by post. This is not a "SQL-grouping", cause you don't need to use some aggregate function on the data, but just to have them organized by post. On your opinion, what's a good way to handle these data? I am going with a foreach and an associative array, but doesn't feel right...
@LaravelDaily
@LaravelDaily 2 жыл бұрын
Why is it not SQL grouping? When doing the query, you group by post_id, and then in the Blade do foreach ($post) -> foreach ($post->comments) etc.
@mikegodz
@mikegodz 2 жыл бұрын
Because when you group by post_id (in SQL syntax) you aggregate the results using count, sum, etc. That's what I mean with "SQL grouping". Are you referring to using the groupBy function of Laravel?
@LaravelDaily
@LaravelDaily 2 жыл бұрын
Yes I thought so, actually thinking about it, it's best to group in collection then, so something like ->get()->keyBy(post_id) or something, don't remember the exact collection method.
@mikegodz
@mikegodz 2 жыл бұрын
@@LaravelDaily Didn't know about the keyBy method. I'll dive into it, thanks!
@hasanbaig1540
@hasanbaig1540 2 жыл бұрын
That's really important topic to follow in development. If you have the right tool then task seems more interesting to do. I haven't found the name of this debugging tool in description please share the link.
@LaravelDaily
@LaravelDaily 2 жыл бұрын
Composer require barryvdh/laravel-debugbar, also Laravel telescope and Spatie Rsy - those are the tools
@GergelyCsermely
@GergelyCsermely 2 жыл бұрын
Excellent. Could You please link the Ray setup video? If I'm not mistaken You have a nice presentation.
@LaravelDaily
@LaravelDaily 2 жыл бұрын
kzfaq.info/get/bejne/pJqggNuqpr7JoY0.html
@GergelyCsermely
@GergelyCsermely 2 жыл бұрын
@@LaravelDaily Thanks
@MrFa321
@MrFa321 2 жыл бұрын
Which server are you using in mac for running laravel applications? Like xampp or any other?
@LaravelDaily
@LaravelDaily 2 жыл бұрын
Laravel valet
@martinlionel7487
@martinlionel7487 2 жыл бұрын
Good video. The most erreur is : use trust orm and don't know how bdd work
@murr3540
@murr3540 2 жыл бұрын
I have an issue, i don't know if its laravel or db issues, but if idle for a certain period of time and tried to retrieve data on the database I got like 1.5k to 3k ms , but on 3rd or 4th call its like on for 400ms, same records it was same records, and I'm using mongodb.
@AbrarAhmad-mz8vl
@AbrarAhmad-mz8vl 2 жыл бұрын
So basically it is issues with queries itself, not with accessor. Is it? If I'm using just get modify date format will it perform bad too?
@hungrybox2100
@hungrybox2100 2 жыл бұрын
Can you please make a video on recursive function when category needs to be display in hierarchy? Because it causes performance problem
@LaravelDaily
@LaravelDaily 2 жыл бұрын
This video should help: kzfaq.info/get/bejne/a9ldkrafu9KRYZs.html
@teb1687
@teb1687 2 жыл бұрын
why are comments being deleted?
@LaravelDaily
@LaravelDaily 2 жыл бұрын
I haven't deleted any comments, except for obvious spam bots
@teb1687
@teb1687 2 жыл бұрын
@@LaravelDaily ok must be some yt issue
@novichkovv
@novichkovv Жыл бұрын
Why don't you use laravel ide helper? My perfectionist eyes are bleeding seeing those inspector warnings. But besides aesthetic aspect, ide helper really improves the quality of code by avoiding typos and development speed by autocomplete. I always try to make each php file having green inspector mark, thus, especially if you use type hints, return types and declare strict, green mark says that everything here is correct and you need to pay attention only to the logic
@alexaverkiyev9099
@alexaverkiyev9099 2 жыл бұрын
The approach of original code was breaking single responsibility principle and was wrong from the very beginning
@kieronwiltshire1701
@kieronwiltshire1701 2 жыл бұрын
Thing is... 700ms is ridiculous for a "production" ready framework
@gianfrancobriones
@gianfrancobriones 2 жыл бұрын
I am guilty
@david-kahly
@david-kahly 2 жыл бұрын
not a good example at all. the code and schema should be refactored.
@dokumentalny
@dokumentalny Жыл бұрын
Names of this metod is a straight from hell 😅 is_ghost - rally?!?
Refactor "Senior" PHP Code with Early Returns
12:09
Laravel Daily
Рет қаралды 25 М.
Junior Code Review: Laravel Routes, Middleware, Validation and more
19:57
UFC 302 : Махачев VS Порье
02:54
Setanta Sports UFC
Рет қаралды 663 М.
it takes two to tango 💃🏻🕺🏻
00:18
Zach King
Рет қаралды 30 МЛН
Did you find it?! 🤔✨✍️ #funnyart
00:11
Artistomg
Рет қаралды 123 МЛН
Eloquent Performance Challenge: My Solution Version
9:57
Laravel Daily
Рет қаралды 19 М.
What is Laravel Octane?
8:34
Aaron Francis
Рет қаралды 28 М.
Laravel Migrations: 12 Useful Tips in 12 Minutes
12:06
Laravel Daily
Рет қаралды 77 М.
Laravel solved race conditions
14:13
Aaron Francis
Рет қаралды 14 М.
Laravel Validation: 12 Less-Known Tips in 13 Minutes
13:11
Laravel Daily
Рет қаралды 37 М.
9 Tips for Shorter Laravel Code
10:16
Laravel Daily
Рет қаралды 60 М.
Top 5 Laravel "Bad Practices" (My Opinion)
10:32
Laravel Daily
Рет қаралды 16 М.
Laravel Pivot Tables: Simple to Advanced Many-to-Many
12:24
Laravel Daily
Рет қаралды 117 М.
Laravel Contracts and PHP Interfaces: Explained with Two Examples
10:10
Getting Started with Laravel Reverb
10:44
Laravel
Рет қаралды 21 М.
chocolate spread vs healthy fruits #dance #challenge
0:11
Super Max
Рет қаралды 18 МЛН
YouTube Play Buttons !! 😱😱
0:17
Tibo InShape
Рет қаралды 12 МЛН
Необычный Способ ОМОЛОЖЕНИЯ😕
0:32
ИССЛЕДОВАТЕЛЬ
Рет қаралды 2,3 МЛН
Они хотели КОЛУ!🤪 inst: psawkin
1:00
Petr Savkin
Рет қаралды 2,7 МЛН