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

Поделиться
HTML-код
  • Опубликовано: 25 апр 2022
  • 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/38b935ad74e5
    Domains on Namecheap - namecheap.pxf.io/rnRjdQ
    Envato Elements - 1.envato.market/c/2937311/298...
    LESSON 3.19
    Course Outline - github.com/ggelashvili/learnp...
    Course Playlist - • Learn PHP The Right Wa...
    RESOURCES
    Source Repo - github.com/ggelashvili/learnp...
    Laravel Eloquent - laravel.com/docs/9.x/eloquent
    Illuminate Database - github.com/illuminate/database
    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.

Комментарии • 76

  • @mwaas
    @mwaas Год назад +3

    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

  • @werrew1238
    @werrew1238 2 года назад +13

    Your lessons are awesome! Good quality, which is not that frequent on youtube. Thank you for your job.

  • @perfect.stealth
    @perfect.stealth Год назад +2

    I could listen to you all day bro. Thanks for your videos.

  • @codingzen869
    @codingzen869 2 года назад +6

    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!!!

  • @jackrourke9237
    @jackrourke9237 2 года назад +3

    Absolutely loved your videos 🥰 🥰 🥰

    • @ProgramWithGio
      @ProgramWithGio  2 года назад +1

      Glad you like them, thank you 💙💙

    • @jackrourke9237
      @jackrourke9237 2 года назад

      @@ProgramWithGio Best to be appreciated ♥ ♥ ♥ ♥ Keep going

  • @emekatimothyiloba699
    @emekatimothyiloba699 10 месяцев назад

    Thank you Gio! This totally makes sense to me as a person coming from a laravel background

  • @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 года назад +1

      Thank you & thank you for the suggestion, I'll think about it

  • @aster_eon
    @aster_eon 2 года назад +2

    First!
    Loving this series ❤️

  • @ousssika5359
    @ousssika5359 4 месяца назад

    man if you do a deep dive like this on laravel your channel will explode

  • @omaryahia
    @omaryahia 4 месяца назад

    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 😄

  • @vitiok78
    @vitiok78 Год назад

    Your videos are really good!

  • @PaulAllsopp
    @PaulAllsopp 6 месяцев назад

    Thanks Gio! I'm building a logistics app right now and was using my own ORM. After watching this I realized how similar my ORM was with Eloquent but Eloquent has a lot more functionality, and less boilerplate (my ORM uses field attributes to describe a model).
    I was just about to start creating my attribute to describe a HasMany relationship and thought I'd see what your thoughts were on the matter.
    Well, now it's 1:35 am, and it's time for a refactor :0)

    • @ProgramWithGio
      @ProgramWithGio  6 месяцев назад

      Heh, yes eloquent is great & so is doctrine ORM but doctrine is a bit more complicated

  • @RealHomeboy
    @RealHomeboy Год назад +1

    This is the reason I want native Doctrine support in Laravel..

  • @yuriymiroshnychenko5446
    @yuriymiroshnychenko5446 Год назад +1

    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  Год назад +1

      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.

  • @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 Год назад

      @@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 Год назад

      @@ProgramWithGio Okay thanks Gio

  • @constantinci
    @constantinci 2 года назад +3

    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. 😁

  • @elmarzougui
    @elmarzougui 2 года назад

    Wooow Amazing and great

  • @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  Год назад +1

      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 🤞

  • @xJuriXPL
    @xJuriXPL 2 года назад

    Do you plan to do videos about implementation of DDD in PHP? I'd love to learn this.

    • @ProgramWithGio
      @ProgramWithGio  2 года назад +1

      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  Год назад +1

      Sure but Eloquent uses active record pattern. But agree that it would be nice to have a mapper option.

  • @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

  • @arielenter
    @arielenter Год назад +1

    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  Год назад +1

      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.

  • @Zubbee
    @Zubbee 11 месяцев назад

    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  11 месяцев назад

      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 11 месяцев назад

      @@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  11 месяцев назад +1

      @@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 11 месяцев назад +1

      @@ProgramWithGio oh cool. Understood. Thanks alot Gio

  • @rxxt-sh1vj
    @rxxt-sh1vj 2 года назад

    When will you make a video on the Design Patterns like factory pattern, middleware etc

    • @ProgramWithGio
      @ProgramWithGio  2 года назад +1

      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

  • @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.

  • @_nirajghimire
    @_nirajghimire 2 года назад +2

    Laravel, the right way. waiting

    • @ProgramWithGio
      @ProgramWithGio  2 года назад +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!

  • @arielenter
    @arielenter Год назад

    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 Год назад

      I just found it: laracasts laravel 8 from scratch. Thanks a lot.

    • @ProgramWithGio
      @ProgramWithGio  Год назад +1

      Yup, you're welcome

    • @arielenter
      @arielenter Год назад

      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 Год назад +1

      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.

  • @phpisdead
    @phpisdead 2 года назад

    you start making laravel tutorials? thanks

    • @ProgramWithGio
      @ProgramWithGio  2 года назад +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 года назад +1

      @@ProgramWithGio Thanks man , we all waiting for laravel course :D

  • @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 Год назад +1

      @@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.

  • @vitiok78
    @vitiok78 Год назад

    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  Год назад

      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 Год назад

      @@ProgramWithGio I think ActiveRecord is an antipattern. A terrible mixture, which is difficult even to test. DataMapper is much cleaner.