Eloquent withCount with Conditions and Aliases

แชร์
ฝัง
  • เผยแพร่เมื่อ 26 พ.ย. 2024
  • To calculate the related records, we use withCount() in Eloquent. But there are a few "advanced" features I want to show you today.
    - - - -
    Support the channel by checking out my products:
    My Laravel courses: laraveldaily.c...
    Laravel QuickAdminPanel: quickadminpane...
    Livewire Kit Components: livewirekit.com
    - - - -
    Other places to follow:
    My weekly Laravel newsletter: us11.campaign-...
    My personal Twitter: / povilaskorop
  • แนวปฏิบัติและการใช้ชีวิต

ความคิดเห็น • 26

  • @chidiebere
    @chidiebere 2 ปีที่แล้ว +2

    Thank you. This is an eye opener. Not only with withCount, you have shown what it's possible with other eloquent methods for a situation like this.

  • @Niboros
    @Niboros 2 ปีที่แล้ว +2

    Thank you for going the extra mile and showcasing the various posibilities how to implement such a feature, and explaining the recommendations.

  • @dailyd3n
    @dailyd3n 2 ปีที่แล้ว +10

    Thanks for video. And also u can replace in relations: *_male,female "$this->hasMany(User::class)" to "$this->users()->where(....)" 🙂

    • @mibrahim4245
      @mibrahim4245 2 ปีที่แล้ว

      Sorry but can you explain more with one example? ..

  • @p30mehrdad
    @p30mehrdad 2 ปีที่แล้ว +3

    you always surprise us with a new useful tip. thank you.😊

  • @MorshedulArefinBD
    @MorshedulArefinBD 2 ปีที่แล้ว +2

    Excellent Explanation

  • @amirulidzham
    @amirulidzham 2 ปีที่แล้ว +2

    Splendid again. Thanks .

  • @ekpotosammuel6868
    @ekpotosammuel6868 2 ปีที่แล้ว +1

    Thanks for making this video

  • @ivan.silicin
    @ivan.silicin 2 ปีที่แล้ว +1

    Thank you, just what I need.

  • @kinanmissing
    @kinanmissing 2 ปีที่แล้ว +1

    super surprise thank you so much solved my problem

  • @bhaveshverma8629
    @bhaveshverma8629 2 ปีที่แล้ว +1

    Thank. Very good 👍👍👍👍👍👍

  • @AMoktar
    @AMoktar 2 ปีที่แล้ว +1

    Thats awesome thanks

  • @hadidagher9443
    @hadidagher9443 2 ปีที่แล้ว +3

    great video as always, what about this: users->groupBy(x) // 5 groups
    How to count groupBy elements?

    • @LaravelDaily
      @LaravelDaily  2 ปีที่แล้ว

      Impossible to answer without exact example: grouping may happen with raw query, with eloquent, with collections, depending on the situation.

  • @neerajsinghtangariya2587
    @neerajsinghtangariya2587 2 ปีที่แล้ว

    🔥

  • @freejobsadda2018
    @freejobsadda2018 ปีที่แล้ว

    Hi sir i need code for a project i will pay u money for that

  • @entertaint3045
    @entertaint3045 2 ปีที่แล้ว

    you r amazing.. do you have vid laravel websocket.. sory out of topic.. 😅😅

    • @LaravelDaily
      @LaravelDaily  2 ปีที่แล้ว

      No, and that's why: twitter.com/PovilasKorop/status/1470640480593801216

    • @entertaint3045
      @entertaint3045 2 ปีที่แล้ว

      @@LaravelDaily great.. thanks

  • @tenzinchemi1459
    @tenzinchemi1459 2 ปีที่แล้ว +1

    Male/Female/Others

  • @janugameryt5893
    @janugameryt5893 ปีที่แล้ว

    sir i want simple senario please give me

  • @tstarfish8829
    @tstarfish8829 2 ปีที่แล้ว

    I don't understand why are you adding extra words related:/column:/operator: into hasMany(...) function, when it works also without it. And it is not in the Laravel doc. like that.

    • @LaravelDaily
      @LaravelDaily  2 ปีที่แล้ว +1

      PHPStorm does that for me automatically, these are hints, not the code.

  • @GC_WK2
    @GC_WK2 2 ปีที่แล้ว +2

    why female relation repeat the code? I think better return $this->users()->where('gender','female');

  • @KnightYoshi
    @KnightYoshi 2 ปีที่แล้ว +1

    I'd call `where` off of the existing `users()` method just to prevent that duplication
    public function users_male(): HasMany {return $this->users()->where(...);}