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 👏👏
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.
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 😅
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.
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.
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.
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.
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 ,…..
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().
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.
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
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 Tks for the answer. It looks very good. Docker became lazy because of the sync of files between container/local env even using :delegated
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 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.
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
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
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
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 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
@@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.
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
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();
I am Brazilian and like very much your videos.
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.
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 👏👏
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.
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
Exactlly i see a lot of people doing that.
In certain cases it's better to use raw sql then query builder. Also proper db indexing is important factor.
My rule:
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 😅
When using eager loading you may need to check if the data was loaded. For that Laravel has the function "relationLoaded".
Very specific and detail example. Very helpful.
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.
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.
Thanks a lot again Povilas for making these videos.
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.
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.
I don't remember them, to be honest, it was a long time ago, I just remember the surprised feeling about it.
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 ,…..
Whoa, this is huge, I've been using with incorecctly. Thank you
Very helpful. Thank you.
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().
Thanks as always. Saved to watch later. Keep the hard work!
Such great content! Thank you very much!!!!
Thanks alot for these advices!
Nice video Povilos 👍
Keep up the good work.
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.
Composer require barryvdh/laravel-debugbar
@@LaravelDaily ooh it was composer library, I thought it was some new laravel feature. thanks
What is the better: $user->posts->count() or count($user->posts) ?
Probably same
Hi sir, thanks for tips. Can you tell us, is there any tool for REST API debugging for laravel like Laravel Debugbar?
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.
Telescope and Ray, a few videos about them: ruclips.net/user/LaravelDailysearch?query=debug%20api
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.
I think you can still use the Debugbar but you have to use the backend url with /api/posts like localhost: 8000/api/posts
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
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 ?
Informative, thanks for sharing.
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.
Laravel valet on my MacBook
@@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
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?
Send me the code to povilas@laraveldaily.com maybe it's worth shooting a video about.
@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.
It's Laravel Debugbar
Wow, really good tips
This was helpful, thank you
Thank you very much sir
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
When you query only a select few columns of a relationship, should we do that within the with() call, or in the get() call?
It should be within with()
For example retrieving comment relation with required fields;
with('comment:id,user_id,text,created_at')
@@gabrielilochi7840 Thanks mate 👍
Thanks, quite useful
Good,but how to get the user avatar in or other map fields in this query.
Thank you.
thanks for these tips
Thanks sir
could you review Encore\Admin\Layout\Content approach for rendering views ( from z-song/laravel-admin package)
I don't think this individual case would be very useful for the audience.
any alternative to debugbar for laravel + SPA configs?
Laravel Telescope
Thanks
In laravel debugger What does the model indicate? Like models 300, like models 120
The amount of Laravel eloquent models saved to RAM during this request.
How can I reduce amount of Laravel eloquent models
May i know what is the package name or extension you use like inspect elements for laravel?
Laravel Debugbar
@@LaravelDaily Thank you for the noticed :D
you look like Mauricio Pochettino
Indeed :)
Using Withcount takes 5.15 ms whereas with eager loading it takes only 2.1 ms which one is better in terms of performance
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
Fastest: use mysql LOAD DATA INFILE
Or laravel lazy collections + chunked inserts
@@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
What should I do if I want to join across 4 four tables? The "hasManyThrough" seems only support 3 tables.
Do manual ->join()
Thanks.
Thx
what is the benefit of compact() ?
Shorter syntax for array
thanks
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
Laravel docs: laravel.com/docs/8.x/eloquent-relationships#counting-related-models
What console log are you using for this?
Laravel Debugbar
@@LaravelDaily can I use it when I only use laravel as an api endpoint?
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?
Where exactly have you seen them, in what context? Can you give me the example/link?
@@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
How to use laravel debugger ? Can you please assist me in this regard?
Google "laravel Debugbar" and read its documentation
@@LaravelDaily Thanks a lot for your kind reply. I have installed successfully.
How do we know if we create an inefficient query?
Hard to answer in a RUclips comment. Emmm, you measure it against other possible queries?
What happens when I don't solve N+1 problems? Someone helps. Thanks
App performance will be drastically reduced...
Great as alwayes
Who can I test these kind of mistakes for API request or controller
With Laravel Telescope
@@LaravelDaily Thanks I will try Telescope
good
How to secure .evn file in laravel.
Don't push it to GitHub
@@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.
amaizng
Spasibo!
Awesome
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
I have a full course: laraveldaily.teachable.com/p/how-to-structure-database-in-laravel
Also, an old video: ruclips.net/video/RbKEYDtkAJI/видео.html
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();