Single-Table Inheritance with Laravel

Поделиться
HTML-код
  • Опубликовано: 11 июн 2021
  • 👨‍💻 Learn Test-Driven Development with Laravel!
    tddwithlaravel.com
    Sign up to 30 Days of Laravel 👉🏻 30daysoflaravel.com
    Parental by Caleb Porzio: github.com/calebporzio/parental
    👨‍💻 Sign up to my newsletter and receive PHP, JS and Laravel news in a weekly-basis:
    subscribe.mateusguimaraes.com
    🎉 Party up:
    / mateusjatenee
    / mateusjatenee
    / mateusguimaraes
    Thanks for watching!

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

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

    you are the best, until now no one had explained this in much time and you did it super well, as well as the syntax of laravel. . Many Thank you so much thanks for the video. I would like a video with multi - table inheritancethat I can not find any explanation yet

  • @asifm3520
    @asifm3520 3 года назад +3

    Really awesome explanation. Looking forward for episode 2.

  • @Claudio_Pereira
    @Claudio_Pereira 3 года назад +1

    Mateus, thanks for the great video. His explanation was so clear that it made it easy to understand a complex topic like this! I'm looking forward to the next video!

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

    Fantastic explanation! Opened my mind.

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

    Love this, it seems like such a cool pattern, I can't wait to try it out.

  • @francois-xaviergourves156
    @francois-xaviergourves156 2 года назад

    This was very helpful for me ! Thank you !

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

    Super interesting. Can’t wait for next part. Really exited about the solution for collections...

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

    Thank you very much
    I have been struggling with this for a while.

  • @emadabulebda5573
    @emadabulebda5573 3 года назад +1

    Really thank you 🙏

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

    Great video!

  • @sjrcube
    @sjrcube 3 года назад

    Thank you so much!

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

    This is awsome 😍😍😍. I have been loooking for pattern like this for weeks. You are a true savior ❤️. You can explain all laravel advanced concepts as clear as diamonds... thank you 👏👏

  • @ertan-ercan
    @ertan-ercan 2 года назад

    I wonder if I can use this pattern for grandchildren structure.
    Imagine there is a Estate Agency Business and Business logic is like this,
    Property Development Site (Grandparent) > Building (Parent) > Property (Child)
    Currenly I solved this with single Property model but I am sure there is better way.

  • @davidtahir1780
    @davidtahir1780 3 года назад

    i want to stick to vanilla laravel without using a plugin and have a problem with single-table-inheritance (STI):
    if i have another class (i.e. "Alert") that is referencing a User via:
    public function user() {
    return $this->belongsTo(User::class);
    }
    And on the User-Class i have:
    public function alerts() {
    return $this->hasMany(Alert::class);
    }
    This will not work with STI.
    If i would call \App\Models\Doctor::all()->first()->alerts an SQL Exception will be fired, telling me, that an unknown column (alerts.doctor_id) is used.
    How do i prevent Laravel from using the wrong foreign-id-field? In this case the field alerts.user_id should be used, as it is derived from the same table.
    Thanks in advance!

    •  3 года назад

      Hey! If you don't want to use a package you'll have to write your own implementation. I suggest you take a look at Caleb's parental package and how it deals with those issues.

  • @SEOng-gs7lj
    @SEOng-gs7lj 2 года назад +1

    how do you deal with models that require additional data? e.g. doctor's specialization qualifications that the nurses don't have?

    •  2 года назад

      You can use the delegated type pattern. Check out my video "Building a timeline like Facebook's"

    • @SEOng-gs7lj
      @SEOng-gs7lj 2 года назад

      @ but that will be the opposite of what is shown here.. i would like to stick to single-table as doctors and nurses share quite a number of common fields

    •  2 года назад

      @@SEOng-gs7lj you can add nullable columns and determine which models will use them

    • @SEOng-gs7lj
      @SEOng-gs7lj 2 года назад

      @ haha okayyy.. i was hoping there was an even cooler way to do it thanks!

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

      @@SEOng-gs7lj I'm kind of no-useless-nullables guy. In that case, I would use Multi-Table Inheritance instead of STI. Probably what he meant as "delegated type pattern". There is no other way around it. You either have 1 giant table with lots of nullables, or create multiple tables.