Тёмный

What is active record pattern & how Laravel implements it with Eloquent - Full PHP 8 Tutorial 

Program With Gio
Подписаться 55 тыс.
Просмотров 15 тыс.
50% 1

In this lesson, we go over what an active record pattern is & how Laravel implements it in its ORM package called Eloquent. This lesson also covers the basics of eloquent to get you familiar with it & show you the differences between the data mapper & active record patterns.
SOME OF THE WAYS YOU CAN SUPPORT THE CHANNEL
👍 Smash the like button
🤝 Subscribe to the channel & turn the notifications on
💬 Post comments, any feedback is greatly appreciated
⭐ Become a Patreon: / programwithgio
THANK YOU!
🛠️ TOOLS & SERVICES I USE
Digital Ocean Hosting - Get 100$ credit - m.do.co/c/38b9...
Domains on Namecheap - namecheap.pxf....
Envato Elements - 1.envato.marke...
LESSON 3.19
Course Outline - github.com/gge...
Course Playlist - • Learn PHP The Right Wa...
RESOURCES
Source Repo - github.com/gge...
Laravel Eloquent - laravel.com/do...
Illuminate Database - github.com/ill...
Lesson 2.12 - Magic Methods - • What Are PHP Magic Met...
** Affiliate Disclaimer: Some of the above links may be affiliate links, which may generate me a sales commission at no additional cost to you.

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

 

15 сен 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 78   
@mwaas
@mwaas Год назад
Everyone explains how to use the technique but You explain how it works and how it was built This makes things clearer and easier, and this is the right way
@ProgramWithGio
@ProgramWithGio Год назад
Glad you like it 🙌
@benderbg
@benderbg 4 дня назад
This was the most intensive lesson so far. I inspected more methods than traffic cams license plates. Thanks!!
@ProgramWithGio
@ProgramWithGio 3 дня назад
happy to hear :)
@werrew1238
@werrew1238 2 года назад
Your lessons are awesome! Good quality, which is not that frequent on youtube. Thank you for your job.
@ProgramWithGio
@ProgramWithGio 2 года назад
Glad you like them. Thank you
@perfect.stealth
@perfect.stealth Год назад
I could listen to you all day bro. Thanks for your videos.
@ProgramWithGio
@ProgramWithGio Год назад
I appreciate that, thank you 💙
@codingzen869
@codingzen869 2 года назад
Couple of topics request if you please cover. One is design patterns in PHP, like singleton, factory, etc. And the other one is, maybe a couple of dedicated videos on DSA with PHP. Great great stuff you are covering in your videos!!!
@ProgramWithGio
@ProgramWithGio 2 года назад
Thank you for the suggestions
@jackrourke9237
@jackrourke9237 2 года назад
Absolutely loved your videos 🥰 🥰 🥰
@ProgramWithGio
@ProgramWithGio 2 года назад
Glad you like them, thank you 💙💙
@jackrourke9237
@jackrourke9237 2 года назад
@@ProgramWithGio Best to be appreciated ♥ ♥ ♥ ♥ Keep going
@ousssika5359
@ousssika5359 8 месяцев назад
man if you do a deep dive like this on laravel your channel will explode
@ProgramWithGio
@ProgramWithGio 8 месяцев назад
Thank you, will try my best
@omaryahia
@omaryahia 8 месяцев назад
Wow 😄 at 35:42 you talked about the collection from query builder vs collection from Eloquent I was just reading this in page 106 in Laravel Up & Running , hahaha 😄 I have a daily routine, a part of it is to study from Laravel Up & Running -> then watch Gio video from where I have stopped last time & summarize in notion I was just reading the same information in the book minutes ago and then came here to see it exactly the same 😄
@ProgramWithGio
@ProgramWithGio 7 месяцев назад
Thats great
@emekatimothyiloba699
@emekatimothyiloba699 Год назад
Thank you Gio! This totally makes sense to me as a person coming from a laravel background
@ProgramWithGio
@ProgramWithGio Год назад
That's awesome, happy to hear
@Zubbee
@Zubbee 2 года назад
Wow. Laravel's eloquent is Soo cool... Lots of magic... I'm left wondering how laravel/eloquent implements it's migrations. I believe I'll probably see more of that in the next lesson. Btw, been dreaming and daydreaming of code for a while now. Gio your tutorials are really turning me into a PHP programmer. Hmmmmm. I appreciate much Gio. I really do.
@ProgramWithGio
@ProgramWithGio 2 года назад
Awesome, glad you like it. Don't think we'll cover laravels migrations in this series, maybe in Laravel course. But it's pretty much the same. If you understand Doctrine migrations, laravels migrations is simpler & easier.
@Zubbee
@Zubbee 2 года назад
@@ProgramWithGio ok. No qualms. I'm sure the magic there too will make things easier. And thanks again for recommending where to learn laravel. I'll probably head there when I finish this course. And then, symphony is an alternate framework right? Which would you recommend for learning, laravel or symphony?
@ProgramWithGio
@ProgramWithGio 2 года назад
@@Zubbee yes, Laravel is easier to learn for a beginner so I would recommend Laravel first
@Zubbee
@Zubbee 2 года назад
@@ProgramWithGio Okay thanks Gio
@yuriymiroshnychenko5446
@yuriymiroshnychenko5446 Год назад
Great video as always! It's very helpful to see the differences between Eloquent and Doctrine side by side. I personally like both. We use Laravel and Eloquent in a large project without any particular complaints. But while Eloquent, using its magic, makes it easy but a bit messy to work with models and queries, Doctrine feels cleaner and more intuitive. Eloquent provides scope methods to prevent duplication, but it still doesn't allow to separate business logic from queries, which is possible with the Repository pattern and Doctrine (Repository pattern and Eloquent is not a good idea, we tried 🙂). So for projects with complex architecture, I would probably go with Doctrine. Laravel and Eloquent are great for simple projects and especially prototyping. But this is a subjective opinion. Thank you for your job!
@ProgramWithGio
@ProgramWithGio Год назад
Thank you, glad you liked it. I personally have used Eloquent on rather large project & did not face any issues. It mainly depends on how you use it, sometimes the magic gets in the way but it makes up by being flexible & easy to work with, less boilerplate, etc. I like Doctrine as well even though I don't use Doctrine day-to-day, I like Data Mapper pattern.
@vitiok78
@vitiok78 2 года назад
Your videos are really good!
@ProgramWithGio
@ProgramWithGio 2 года назад
Glad you like them, thank you
@RealHomeboy
@RealHomeboy Год назад
This is the reason I want native Doctrine support in Laravel..
@ProgramWithGio
@ProgramWithGio Год назад
That would be pretty cool indeed
@constantinci
@constantinci 2 года назад
It's not my tale (Laravel and all around), but as always, great educational and at the same time concise elaboration. I am running out of unique expressions for my appreciation. 😁
@ProgramWithGio
@ProgramWithGio 2 года назад
Thank you 💙💙
@KIKOmanasijev
@KIKOmanasijev Год назад
You can use ChatGPT now 😂
@abdelrahmanmagdy3706
@abdelrahmanmagdy3706 2 года назад
One of the best channels I have ever followed .. just one request please could you make a video about the integration tests and the e2e tests
@ProgramWithGio
@ProgramWithGio 2 года назад
Thank you & thank you for the suggestion, I'll think about it
@aster_eon
@aster_eon 2 года назад
First! Loving this series ❤️
@ProgramWithGio
@ProgramWithGio 2 года назад
Yay! Thank you 💙💙
@arielenter
@arielenter 2 года назад
This is the first time I'm learning OOP. I can't imagine I would have ever learn to use a framework the right way without knowing all this concepts and how they work. I'm sure you have mentioned many times, but isn't this the objective of the course? So that we are not dependent of a single framework? You mention many times that we should not use this classes and methods on production, witch in my mind sounds like we will end up using framework instead, once we understand what is a framework purpose first. I totally agree with that statement. If I had tried to learn a specific framework from the start, it probably wouldn't had been feasible, and I would most probably had learned like a parrot without understanding what I was doing. I started this course late, so I'm lucky there were a lot of your videos already out for me to study, and knowing what I have said above, I most probably should be patience, but I'm not. Would it be OK if I start learning laravel while your next video is out? We haven't touch views for example but I'm sure laravel has a way to handle those too. Any way, I'm not trying to pressure you or anything, I think you are making an incredible job at this rate, but I can't even imagine that we are close to start making things for production any soon. So my plan is to start learning laravel and keep an eye on you new videos, because they most probably help me understand what ever I'll be doing on laravel by that time. I respect a lot your opinion, so if you want to suggest me otherwise I'll wait. If you have a time frame you believe you end the series I'll be nice to know it too. Thank you.
@ProgramWithGio
@ProgramWithGio 2 года назад
Thank you very much. We are going to work on a project at the end of the series, that being said, you can for sure start learning Laravel and if you have trouble understanding a specific topic come to this series & look for a video about that topic, there is a good chance you'll find it here & it might help you understand that topic better. I don't have a timeframe but we are close to ending the series.
@_nirajghimire
@_nirajghimire 2 года назад
Laravel, the right way. waiting
@ProgramWithGio
@ProgramWithGio 2 года назад
👀👀
@roky2822
@roky2822 2 года назад
I support! I see so much trash laravel code nowadays my eyes bleed. Yet I myself sometimes am unsure what the best ways are to some architectural decisions to manage complexity as best as possible.
@itwebadmin
@itwebadmin 2 года назад
Shit we already got Gio PHP Gio Laravel up next!
@mouhamaddiop1144
@mouhamaddiop1144 Год назад
Pourriez vous nous faire un tutoriel sur le framework Laravel ? ça fait bientôt deux ans que je l'utilise mais je suis sûr d'en apprendre encore plus avec vous.
@ProgramWithGio
@ProgramWithGio Год назад
Yes, probably in 2023
@obadaalzidi6452
@obadaalzidi6452 2 месяца назад
Hi Gio, Thanks for this great video ! I would like to use the save() method on parent / child models over using push() on the parent model, because I think that the push() method will loop on every relation on the parent model and then it will loop on every model within the relation and then call the push() method on it ! So it should be much slower right ?
@ProgramWithGio
@ProgramWithGio 2 месяца назад
Yes, it depends on how many relations your model has & whether you want to make that tradeoff or not
@elmarzougui
@elmarzougui 2 года назад
Wooow Amazing and great
@ProgramWithGio
@ProgramWithGio 2 года назад
Thank you
@xJuriXPL
@xJuriXPL 2 года назад
Do you plan to do videos about implementation of DDD in PHP? I'd love to learn this.
@ProgramWithGio
@ProgramWithGio 2 года назад
I haven't done much of DDD and would not feel comfortable teaching it. @JustSteveKing does content around DDD so I would suggest to check out his channel
@bijianwu5124
@bijianwu5124 Год назад
thanks for the great content once again! don't you think it would be good that Eloquent could have data mapping built in? so that we can access the property field like unitPrice instead of unit_price, unit_price breaks the variable naming convetion in PHP in my opnion, it looks so odd to access a field like $model->unit_price.
@ProgramWithGio
@ProgramWithGio Год назад
Sure but Eloquent uses active record pattern. But agree that it would be nice to have a mapper option.
@ibrahemmohammad8332
@ibrahemmohammad8332 Год назад
thank you for a great video ,as always it has been helpfull, i wanted to ask you what framwork do you recommend learning (laravel , Yii) or some other framwork in a way that will help me get a job ... i worked with both laravel and yii , both are amazing but i don't have mush experience in them , so in which of them i should dive in or should i learn some other framework to increase my chances to get a job ??
@ProgramWithGio
@ProgramWithGio Год назад
There are a lot of Laravel jobs in the market. I haven't seen much for Yii so I'm not sure. I would say learn Laravel but that might be a bit biased since I use & work with Laravel and haven't worked with Yii. That being said, I personally would dive into Laravel more. Hope this help & good luck 🤞
@rxxt-sh1vj
@rxxt-sh1vj 2 года назад
When will you make a video on the Design Patterns like factory pattern, middleware etc
@ProgramWithGio
@ProgramWithGio 2 года назад
Those won't be part of this PHP series, it will be a separate standalone video probably. Don't know when yet since I have this PHP series to finish & then Laravel+Shopify one
@ntdash2153
@ntdash2153 Год назад
Quick question: Is there a way to bind a column to a property instead of the one generated by Laravel's active record pattern? In other terms, replicate the exact behavior of #[Column(name: "column_name"] seen in the data mapping pattern.
@ProgramWithGio
@ProgramWithGio Год назад
You can just define a property but no data mapping like in Doctrine because it's active record
@Zubbee
@Zubbee Год назад
Hi Gio, just need to ask this. With doctrine, after mapping the the entities we run the migrations to create the tables and its columns. But with eloquent here we had the table already and eloquent helped to map to the existing table and its columns (with the snake naming convention). So with eloquent we have to create the tables first and then the models will map to them? Or we can also create the models and use migrations to create the table with its columns?
@ProgramWithGio
@ProgramWithGio Год назад
We didn't run migrations with eloquent because we already had tables created. If you start a fresh app with Eloquent then you will still need to run migrations to create tables. As far as the column mapping, yes Laravel does the mapping for you
@Zubbee
@Zubbee Год назад
@@ProgramWithGio ok. So then you won't have to specify the properties on a new model that will become columns on the new table when you run the migrations right?
@ProgramWithGio
@ProgramWithGio Год назад
@@Zubbee not inside model. You define columns in migration so that it creates the table. In Laravel you create migration first, in doctrine you create entity and generate migration from it but in Laravel you typically create migration on your own, define columns, run the migration and then create Model which automatically has access to those columns from the table
@Zubbee
@Zubbee Год назад
@@ProgramWithGio oh cool. Understood. Thanks alot Gio
@arielenter
@arielenter 2 года назад
I believe you mentioned a series of videos to learn laravel, but the video is so long I just can't find it anymore. What was series of videos you mentioned?
@arielenter
@arielenter 2 года назад
I just found it: laracasts laravel 8 from scratch. Thanks a lot.
@ProgramWithGio
@ProgramWithGio 2 года назад
Yup, you're welcome
@arielenter
@arielenter 2 года назад
It is too bad, but it seems that the tutorial I found using the description "laravel 8 from scratch" only has 10 episodes and no new video has been uploaded since July of last year. I'll look for another tutorial. Thank you.
@arielenter
@arielenter 2 года назад
never mind, I just look it up and the series is complete in the official website. The tutorial I mentioned was from youtube. Thank you.
@truthteachers
@truthteachers Год назад
Bro, i am really sorry, its seems to be messing things up. In the previous videos we had already created the "Invoice" model and now in this video you create a duplicate. We have been retaining all the codes from the previous videos for reference purposes and now you create a new Invoice model which breaks all our previous codes. Please advise.
@ProgramWithGio
@ProgramWithGio Год назад
This one is for active record example. These codes are not meant to be saved/used in production. They are just examples. We write project later and start over so you don't need to save any of it, just use it for practice and move on to next lesson. Previous lessons were Doctrine examples, this one is active record example. I kept both so that you can compare and see the difference between data mapper & active record. You can think of this as a playground until we start working on the project.
@truthteachers
@truthteachers Год назад
@@ProgramWithGio I understand. I am not using this in production but by coding the scripts line by line i try to analyze and understand. In many of the previous lessons you carried forward the code as continuation. Especially until this one, where all the classes were still used. Anyway, no worries. i created a duplicate of the scripts with another name e.g I created Invoicex class instead of Invoice class. Its works fine. In my opinion, prefer Eloquent compared to Doctrine, simpler and closer to reality. Doctrine seems too spaghetti for me. Beginning to understand Codeigniter 4 and Laravel better now. Thank you so much, bro.
@phpisdead
@phpisdead 2 года назад
you start making laravel tutorials? thanks
@ProgramWithGio
@ProgramWithGio 2 года назад
No, this is part of the PHP series, topic is Active Record pattern & Eloquent is a good example of it so decided to cover the basics of it to show how active record works & how it compares to the data mapper pattern that we covered previously (doctrine).
@phpisdead
@phpisdead 2 года назад
@@ProgramWithGio Thanks man , we all waiting for laravel course :D
@vitiok78
@vitiok78 2 года назад
Wow! I didn't even know that Doctrine is so much better than Eloquent. Eloquent is a magic mess. I don't like it at all.
@ProgramWithGio
@ProgramWithGio 2 года назад
Eloquent is great, it mainly depends on the use case as well as the developer's preference. I like eloquent a lot and have used in large applications without any issues.
@vitiok78
@vitiok78 2 года назад
@@ProgramWithGio I think ActiveRecord is an antipattern. A terrible mixture, which is difficult even to test. DataMapper is much cleaner.
Далее
PHP on the frontend! No more Javascript!
14:47
Просмотров 122 тыс.
ЗАБЛУДИЛИСЬ В ТРАВЕ #shorts
00:25
Просмотров 419 тыс.
Тарковский - гений
00:48
Просмотров 563 тыс.
PHP is the future
34:27
Просмотров 176 тыс.
Rust For PHP Developers
59:42
Просмотров 25 тыс.
PHP Generators Explained - Full PHP 8 Tutorial
25:47
Просмотров 30 тыс.