Eloquent withCount with Conditions and Aliases

Поделиться
HTML-код
  • Опубликовано: 1 окт 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

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

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

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

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

  • @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(...);}

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

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

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

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

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

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

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

    super surprise thank you so much solved my problem

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

    Thanks for making this video

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

    Thats awesome thanks

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

    Splendid again. Thanks .

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

    Excellent Explanation

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

    Thank. Very good 👍👍👍👍👍👍

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

    sir i want simple senario please give me

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

    Male/Female/Others

  • @ivan.silicin
    @ivan.silicin 2 года назад +1

    Thank you, just what I need.

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

    🔥

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

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

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

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