4,365 views
This video is about PHP generators and LazyCollection. We'll use an example to see how generators can optimize memory usage. Let's pay attention to where generators are used in laravel, how convenient it is for us to use them and when. #LazyCollections#PHP#laravel#cutcode --------------------------------------------------------------------------------- ???????????????? How about upgrading your skills with our web development training video courses? Go to my website ???? https://learn.cutcode.dev/?utm_source=yt ❗️❗️❗️Join our community on Telegram - they'll help you with advice and a lot of interesting things - https://goo.su/dsGP7PI --------------------------------------------------------------------------------- I welcome all laravel fans to the CutCode channel! Today we'll talk about PHP generators. About this scary word vield and again we will implement an example that everyone does in training videos and articles. With a huge array, which is formed by the Range function. But friends, I am deceiving you and in fact we will not do this. There are already thousands of videos about generators and their wonderful effect on memory. All of them are within the framework of the example with an array built on the Range function. The same goes for articles and the documentation itself. And you have all seen it many times already. And for those who have not seen it, I recommend watching or reading. But I think in the end after studying you will be satisfied - you understood everything. But where to apply, when to apply you still do not know. And after a couple of hours you will forget about them altogether. Therefore, we will discuss their essence a little, literally a couple of sentences, but we will talk about a specific application. Where they are used in laravel, how it is convenient for us to use them and when. Well, let's go! Friends, a problem. Let's say we need to interact with models and, for example, calculate something based on them. And we need models with casts and other things. We have an entity - we take all the records - in this case there are 10k records. We do the process itself somewhere in a console command on a schedule and calculate something in some entity. As a result, such a request will form a collection of ten thousand models at the output. Pay attention to how much memory we needed for this - as much as 30 megabytes. And here there are only 10k records. If we talk about SQL queries and query builder, then the cursor method can come to our aid. Let's use it instead of All, and then delve into the method itself. And here we will see that it works just on the generator, here is our favorite vield. And it is not just a collection that helps it, but a Lazy collection. --------------------------------------------------------------------------------- ???? share this video with your friends: • LazyCollections and PHP generators. How... ???? subscribe to the YouTube channel: https://www.youtube.com/c/CutCodeRu?s... ???? Laravel course from scratch: • Laravel 8 course training from scratch. Be... NAMENAMENAME --------------------------------------------------------------------------------- ???? our website: https://cutcode.dev/?utm_source=yt ???? Our telegram channel: https://t.me/laravel_cutcode