Тёмный

Eloquent Performance: TOP 3 Mistakes Developers Make 

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

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

 

2 окт 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 111   
@PauloRicardo-dk6yf
@PauloRicardo-dk6yf 3 года назад
I am Brazilian and like very much your videos.
@sodomousprime
@sodomousprime 3 года назад
The last one is like when you have a HTML select input, where you only need the "id" and the "title" rather than loading all of the rest of the data. Good video, cheers.
@ClCfe
@ClCfe 3 года назад
Model::pluck('title', 'id'); Be careful, do not do Model::get()->pluck('title', 'id'); As it does a Select * and then call pluck on the collection
@nadjimmalade2847
@nadjimmalade2847 3 года назад
Exactlly i see a lot of people doing that.
@mahdihassannejad6157
@mahdihassannejad6157 3 года назад
I should thank you a lot Povilas, I always start my day by watching one of your videos, And it would opens my mind along the day.
@Bevallalom
@Bevallalom 3 года назад
In certain cases it's better to use raw sql then query builder. Also proper db indexing is important factor.
@ihorchyshkala6325
@ihorchyshkala6325 2 года назад
My rule:
@Stoney_Eagle
@Stoney_Eagle 3 года назад
When a TV show has casts, crews, posters, backdrops, translations, trailers and seasons, seasons has translations and episodes, episodes has translations and a video file and video file has a progress you learn quick to do all these eager loadings on the database level, not to mention using the right indexes on the keys your relations uses. That saves 2 to 5 minutes and 500mb on the worst case scenario 😅
@KirillHybrid-f4f
@KirillHybrid-f4f 3 года назад
One more important thing, it's very easy to use model $with variable to eager load relationship. But in much cases this data isn't used for example in model index. In that cases you can see how the performance decrease, specially with polymorphic relationship. It's better to retrieve relationships only for show and edit methods, where they will be really used, but not always through the model $with.
@nabeelyousafpasha
@nabeelyousafpasha 3 года назад
Do you mind sharing those examples where PHP manipulation was seen more speedy than MySQL? Please share your experiences. Eager to learn more from you. Respect from Pakistan.
@LaravelDaily
@LaravelDaily 3 года назад
I don't remember them, to be honest, it was a long time ago, I just remember the surprised feeling about it.
@maxpower7735
@maxpower7735 3 года назад
When using eager loading you may need to check if the data was loaded. For that Laravel has the function "relationLoaded".
@abdulbasitsalah2918
@abdulbasitsalah2918 3 года назад
i like how you categorize your video with the related topic for example in this video you prefix title with "Eloquent Performance:" it will be so good when someone search for performance in channel 👏👏
@nurudeenqoyyumtimilehin5475
@nurudeenqoyyumtimilehin5475 3 года назад
Informative, thanks for sharing.
@daleryanaldover6545
@daleryanaldover6545 3 года назад
Another way to explain $user->post->count() is that when we load a model either with relationship or not the returned data is a collection instance. And in the collection documentation we have ->count() method that counts data from the returned collection and not from databse.
@sumanthapa4670
@sumanthapa4670 3 года назад
Sir, I need to load 10 different kind from database news table based on their category which would be faste method 1:- $news_cat_1 = News::where('cat_id','1')->get(); $news_cat_2 = News::where('cat_id','2')->get(); . . . $news_cat_10 = News::where('cat_id','10')->get(); Method 2: $allNews = News::all(); $news_cat_1 = $allNews->where('cat_id','1')->get(); $news_cat_2 = $allNews->where('cat_id','2')->get(); . . . . $news_cat_10 = $allNews->where('cat_id','10')->get();
@jing4625
@jing4625 2 года назад
Thx
@raphaeld7308
@raphaeld7308 3 года назад
you look like Mauricio Pochettino
@henriquefriedrich5960
@henriquefriedrich5960 3 года назад
Indeed :)
@shahosanandaji9894
@shahosanandaji9894 2 года назад
Thanks a lot again Povilas for making these videos.
@naturallifenow
@naturallifenow 3 года назад
Great! I made the 3rd mistake too much when I made PDF reports that contained more than 10,000 records. Instead of creating a ReportResource with only the fields needed for the report, I used a Resource that returned all the fields in the table. For many records, it makes a total difference in the total size of json that the frontend needs to download from the backend.
@rizkiakbar4866
@rizkiakbar4866 2 года назад
I new on laravel thanks for your helpfull video. How do u can view that's laravel process windows down there ?. I had no idea how to do that.
@LaravelDaily
@LaravelDaily 2 года назад
Composer require barryvdh/laravel-debugbar
@rizkiakbar4866
@rizkiakbar4866 2 года назад
@@LaravelDaily ooh it was composer library, I thought it was some new laravel feature. thanks
@jacquesmatike9289
@jacquesmatike9289 3 года назад
For the last case, I have a similar problem. In my database, I have almost 13.000 records of users. I have to process them all to get stats of users by checking an attribute value (0, 1, 2, 3). Loading data from database is fast, but process them in the foreach takes 40s. And obviously only that attribute and ID are loaded. Is there a way to do that operation for minimum time?
@LaravelDaily
@LaravelDaily 3 года назад
Send me the code to povilas@laraveldaily.com maybe it's worth shooting a video about.
@iliyasmsc
@iliyasmsc 3 года назад
Good,but how to get the user avatar in or other map fields in this query.
@exikoz
@exikoz 3 года назад
Such great content! Thank you very much!!!!
@mouctechy
@mouctechy Год назад
Thank you sir for sharing it. I would like to know which front end framework do you suggest for a mid beginner of Laravel ? Live wire; vue, reactjs, jet-stream ,…..
@corbitaltechnologies
@corbitaltechnologies 3 года назад
Very specific and detail example. Very helpful.
@abuhenamustafamohammedsaha4386
@abuhenamustafamohammedsaha4386 2 года назад
Using Withcount takes 5.15 ms whereas with eager loading it takes only 2.1 ms which one is better in terms of performance
@tukurhamid
@tukurhamid Год назад
Thank you very much sir
@arnaudbakyono461
@arnaudbakyono461 Год назад
Wow, really good tips
@user-ej4dm2xq6q
@user-ej4dm2xq6q 3 года назад
Very helpful. Thank you.
@abelenocrodriguez
@abelenocrodriguez 3 года назад
How would you do an API to debug this? Please, it would be very interesting to attack this type of problem, basically because my stack in more than 200 projects is always Vue.js and Laravel API
@anastasiospapadopoulos4612
@anastasiospapadopoulos4612 3 года назад
Thanks alot for these advices!
@pacykarz2009
@pacykarz2009 3 года назад
What is the better: $user->posts->count() or count($user->posts) ?
@LaravelDaily
@LaravelDaily 3 года назад
Probably same
@YehudaKatz1
@YehudaKatz1 3 года назад
I do filtering in PHP if whether the user can see an object is based on some permissions. For example, different users in a store have different payment methods available. I can't think of a simple way to filter that in the database. In PHP, you can use Collection::filter() to check if $user->can().
@tim.bogdanov
@tim.bogdanov Год назад
Whoa, this is huge, I've been using with incorecctly. Thank you
@alislim6201
@alislim6201 2 года назад
am using join and leftjoin function in some cases instead of laravel relationship i find that way is better for me do you have any suggestions ?
@afjalhusain302
@afjalhusain302 Год назад
Thanks sir
@masterpreshy9614
@masterpreshy9614 3 года назад
Thank you.
@AbdelrahmanEl.Monshed
@AbdelrahmanEl.Monshed 2 года назад
good
@amitsolanki9363
@amitsolanki9363 8 месяцев назад
In laravel debugger What does the model indicate? Like models 300, like models 120
@LaravelDaily
@LaravelDaily 8 месяцев назад
The amount of Laravel eloquent models saved to RAM during this request.
@amitsolanki9363
@amitsolanki9363 8 месяцев назад
How can I reduce amount of Laravel eloquent models
@RehmanKhan-zv2rl
@RehmanKhan-zv2rl 3 года назад
Great, I was always confuse to use relation with '( )' or without '( )', and also with eager loading, i have cleared the difference between that but can you please define more about eager loading and lazy loading and stuff like that, It would be really helpful. Thanks
@mukhtarhussain2659
@mukhtarhussain2659 2 года назад
amaizng
@noddychoi
@noddychoi 3 года назад
What should I do if I want to join across 4 four tables? The "hasManyThrough" seems only support 3 tables.
@LaravelDaily
@LaravelDaily 3 года назад
Do manual ->join()
@rehmanghani6726
@rehmanghani6726 Год назад
Nice video Povilos 👍 Keep up the good work.
@zafarbekbadalboyev9689
@zafarbekbadalboyev9689 3 года назад
Hi sir, thanks for tips. Can you tell us, is there any tool for REST API debugging for laravel like Laravel Debugbar?
@anthoniG
@anthoniG 3 года назад
I think you can use Laravel Telescope. Don't quote me on that though as I am still relatively new to the whole Laravel experience.
@LaravelDaily
@LaravelDaily 3 года назад
Telescope and Ray, a few videos about them: ru-vid.comsearch?query=debug%20api
@vitorfontoura5417
@vitorfontoura5417 3 года назад
You could use itsgoingd/clockwork. It has a similar feature to debugbar to add a footer with some request information, and in my opinion is a bit simpler than Telescope.
@darkmode404
@darkmode404 3 года назад
I think you can still use the Debugbar but you have to use the backend url with /api/posts like localhost: 8000/api/posts
@SanderCokart
@SanderCokart 3 года назад
what is the benefit of compact() ?
@LaravelDaily
@LaravelDaily 3 года назад
Shorter syntax for array
@MirzaBilal1992
@MirzaBilal1992 3 года назад
How to use laravel debugger ? Can you please assist me in this regard?
@LaravelDaily
@LaravelDaily 3 года назад
Google "laravel Debugbar" and read its documentation
@MirzaBilal1992
@MirzaBilal1992 3 года назад
@@LaravelDaily Thanks a lot for your kind reply. I have installed successfully.
@SanderCokart
@SanderCokart 3 года назад
any alternative to debugbar for laravel + SPA configs?
@LaravelDaily
@LaravelDaily 3 года назад
Laravel Telescope
@ashishdake1197
@ashishdake1197 3 года назад
@LaravelDaily I liked your videos much. Rather I say, I am learning Laravel by watching your videos only. I have a doubt. At 1:30, 2:25 or 5:05 you are showing us DB queries count and all DB queries. How can I see it in my browser. Is there any specific software or chrome extension for it? Also, please share list of all extensions and softwares that you use while development.
@LaravelDaily
@LaravelDaily 3 года назад
It's Laravel Debugbar
@vikymuhamad4226
@vikymuhamad4226 3 года назад
hi sir i still not understand about ur relasi using withCount(posts) and u get data in index using $user->post_count , and ur relasi name is posts , do u can tell me about $user->post_count coz ur name relasi is posts not post_count . thanks
@LaravelDaily
@LaravelDaily 3 года назад
Laravel docs: laravel.com/docs/8.x/eloquent-relationships#counting-related-models
@KevinYobeth
@KevinYobeth 3 года назад
How do we know if we create an inefficient query?
@LaravelDaily
@LaravelDaily 3 года назад
Hard to answer in a RU-vid comment. Emmm, you measure it against other possible queries?
@jomonjohnson735
@jomonjohnson735 3 года назад
could you review Encore\Admin\Layout\Content approach for rendering views ( from z-song/laravel-admin package)
@LaravelDaily
@LaravelDaily 3 года назад
I don't think this individual case would be very useful for the audience.
@bugsbunny4353
@bugsbunny4353 3 года назад
Hi sir Can u make a video on upload large CSV in db fast using queue I worked on it its working fine but due to my server limitation sometimes queue fails
@ClCfe
@ClCfe 3 года назад
Fastest: use mysql LOAD DATA INFILE Or laravel lazy collections + chunked inserts
@bugsbunny4353
@bugsbunny4353 3 года назад
@@ClCfe i am already using laravel jobs by breaking large csv into small files chunks then using jobs to save in background using particular user id
@belce1982
@belce1982 3 года назад
Thanks as always. Saved to watch later. Keep the hard work!
@shaungbhone8368
@shaungbhone8368 3 года назад
What happens when I don't solve N+1 problems? Someone helps. Thanks
@salisu14
@salisu14 2 года назад
App performance will be drastically reduced...
@flyer0022f
@flyer0022f 3 года назад
This was helpful, thank you
@DenisK-v7z
@DenisK-v7z 3 года назад
Spasibo!
@chiragkumar6322
@chiragkumar6322 3 года назад
How to secure .evn file in laravel.
@LaravelDaily
@LaravelDaily 3 года назад
Don't push it to GitHub
@chiragkumar6322
@chiragkumar6322 3 года назад
@@LaravelDaily Thank you sir for reply. but actually my issue it is. I have make a Laravel 5.8 project In which many API are make for android APP. And one user find a bug his using our app and get some error. It shows the code of the .evn file. so how to secure .evn file to get any error.
@heyyy4987
@heyyy4987 3 года назад
Awesome
@jazzlevit
@jazzlevit 3 года назад
Thanks, quite useful
3 года назад
Hi Povilas, nice video. Which is your current stack for php/laravel development locally? I am using docker locally, but your video it seems very faster.
@LaravelDaily
@LaravelDaily 3 года назад
Laravel valet on my MacBook
3 года назад
@@LaravelDaily Tks for the answer. It looks very good. Docker became lazy because of the sync of files between container/local env even using :delegated
@mmramadan496
@mmramadan496 3 года назад
Excuse me, sir I have seen two methods in the Eloquent part are `fresh` and `refresh` BUT I do NOT know what is the benefit of these methods So, can you please explain more about these methods?
@LaravelDaily
@LaravelDaily 3 года назад
Where exactly have you seen them, in what context? Can you give me the example/link?
@mmramadan496
@mmramadan496 3 года назад
@@LaravelDaily I can NOT send the link because every time I send a link it deleted So, search for `Eloquent: Getting Started` in the docs then you'll find the `Refreshing Models` title
@hariomnagar5606
@hariomnagar5606 3 года назад
Who can I test these kind of mistakes for API request or controller
@LaravelDaily
@LaravelDaily 3 года назад
With Laravel Telescope
@hariomnagar5606
@hariomnagar5606 3 года назад
@@LaravelDaily Thanks I will try Telescope
@muaazhammad4446
@muaazhammad4446 3 года назад
thanks for these tips
@codingsense
@codingsense 3 года назад
Good video thanks , can you please make a video on how to design a database digram I struggle a lot with it Please like this comment for him to see this
@LaravelDaily
@LaravelDaily 3 года назад
I have a full course: laraveldaily.teachable.com/p/how-to-structure-database-in-laravel Also, an old video: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-RbKEYDtkAJI.html
@lahcenfahmi5361
@lahcenfahmi5361 3 года назад
Thanks
@sourovahmad4053
@sourovahmad4053 3 года назад
Great as alwayes
@RANJEETKUMAR-wz4dg
@RANJEETKUMAR-wz4dg 3 года назад
thanks
@GergelyCsermely
@GergelyCsermely 3 года назад
Thanks.
@suhpc82
@suhpc82 3 года назад
When you query only a select few columns of a relationship, should we do that within the with() call, or in the get() call?
@gabrielilochi7840
@gabrielilochi7840 3 года назад
It should be within with() For example retrieving comment relation with required fields; with('comment:id,user_id,text,created_at')
@suhpc82
@suhpc82 3 года назад
@@gabrielilochi7840 Thanks mate 👍
@paul.stream24
@paul.stream24 3 года назад
May i know what is the package name or extension you use like inspect elements for laravel?
@LaravelDaily
@LaravelDaily 3 года назад
Laravel Debugbar
@paul.stream24
@paul.stream24 3 года назад
@@LaravelDaily Thank you for the noticed :D
@kevinpallado9638
@kevinpallado9638 3 года назад
What console log are you using for this?
@LaravelDaily
@LaravelDaily 3 года назад
Laravel Debugbar
@kevinpallado9638
@kevinpallado9638 3 года назад
@@LaravelDaily can I use it when I only use laravel as an api endpoint?
Далее
Laravel Junior Code Review: 12 Tips on Everything
15:30
Eloquent Performance Challenge: My Solution Version
9:57
Китайка стучится Домой😂😆
00:18
Laravel Security: Top 7 Mistakes Developers Make
11:16
Faster Eloquent: Avoid Accessors with Foreach
9:35
Просмотров 53 тыс.
Laravel Eloquent: Deeper Relationships with One Query
10:37
Why is Laravel NOT used in Big Development Projects?
11:53
5 tips for supercharged Laravel Eloquent queries
16:29
Eloquent or Query Builder: When to Use Which?
5:48
Просмотров 88 тыс.