I was returning a big JSON column and I didn't know the impact of that until in the pilot test the query took like 5 seconds to get 360 records, from 14MB to 143Kb I didn't realize this until I got this video on my recommended Thanks sir
Thanks for another nice tutorial Povilas. Optimizing the return data is indeed important. However I prefer to use the Laravel-Jory package instead of Laravel's Resource classes because it let's you pick the fields and relations from the frontend. No need to set up a separate Resource class every time you need a different data structure to be returned. (yes, I'm biased. Wrote the package myself 😁)
This is only affects the size of the response, but the speed is not because you are still doing select *, how about including only the columns you want to show in the API Response? how you will do that? Great info thanks.
After one year youtube recommended it again for me with a question after some experience with large data and laravel resources. What to do when you need different type of columns in the same Model/table? Ex: Product Model, in some situations only barcode and name or with price or in other situations whole columns are required.
Please must give me answer, M facing very slow laravel API response. i was thinking that may be database queries are not optimized. What i did is i created new route with closure function and just return empty response, just to check laravel response time. Unfortunately that empty response was also very slow, and it took almost 1100 ms. Plz guide me how to debug and what would be possible reasons for this
Something wrong with your web-server in general, then. It's impossible to blindly guess. Try non-Laravel project. Try non-API project. Find the reason.
If I understand your question correctly, you think there's a double work - return collection and array? In this case, toArray refers to formatting the array of fields, not array of User records. Not sure if it's clear.
@@47Lancelot now thinking about it, maybe you're right and maybe I did mess up some of those parameters, although result seems correct. What would be your way of doing it?
@@47Lancelot then I guess you should read more examples of API Resources and specifically collections: laravel.com/docs/5.8/eloquent-resources#resource-collections
I was returning a big JSON column and I didn't know the impact of that until in the pilot test the query took like 5 seconds to get 360 records, from 14MB to 143Kb
I didn't realize this until I got this video on my recommended
Thanks sir
Thanks for another nice tutorial Povilas.
Optimizing the return data is indeed important. However I prefer to use the Laravel-Jory package instead of Laravel's Resource classes because it let's you pick the fields and relations from the frontend. No need to set up a separate Resource class every time you need a different data structure to be returned.
(yes, I'm biased. Wrote the package myself 😁)
Optimizing this way matters a lot. Thanks and Love from Pakistan.
This is only affects the size of the response, but the speed is not because you are still doing select *, how about including only the columns you want to show in the API Response? how you will do that?
Great info thanks.
in the second parameter of paginate method. You can specify which columns you want to select.
After one year youtube recommended it again for me with a question after some experience with large data and laravel resources.
What to do when you need different type of columns in the same Model/table? Ex: Product Model, in some situations only barcode and name or with price or in other situations whole columns are required.
I have called product model in Sale, in Purchase, and so on...
Thank you sir. This is really helpful for my big project.
That's where GraphQL is really helpful. Did you use it ever? I never did tbh
Please must give me answer, M facing very slow laravel API response. i was thinking that may be database queries are not optimized. What i did is i created new route with closure function and just return empty response, just to check laravel response time. Unfortunately that empty response was also very slow, and it took almost 1100 ms. Plz guide me how to debug and what would be possible reasons for this
Something wrong with your web-server in general, then. It's impossible to blindly guess. Try non-Laravel project. Try non-API project. Find the reason.
noob question: why you use method ::collection but toArray is called?
If I understand your question correctly, you think there's a double work - return collection and array? In this case, toArray refers to formatting the array of fields, not array of User records. Not sure if it's clear.
Povilas Korop so he redefined method toArray which is called by get() ?
@@47Lancelot now thinking about it, maybe you're right and maybe I did mess up some of those parameters, although result seems correct. What would be your way of doing it?
Povilas Korop I’m just trying to understand the video, dude)
@@47Lancelot then I guess you should read more examples of API Resources and specifically collections: laravel.com/docs/5.8/eloquent-resources#resource-collections
Thanks
awesome