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 - แนวปฏิบัติและการใช้ชีวิต
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.
Thank you for going the extra mile and showcasing the various posibilities how to implement such a feature, and explaining the recommendations.
Thanks for video. And also u can replace in relations: *_male,female "$this->hasMany(User::class)" to "$this->users()->where(....)" 🙂
Sorry but can you explain more with one example? ..
you always surprise us with a new useful tip. thank you.😊
Excellent Explanation
Splendid again. Thanks .
Thanks for making this video
Thank you, just what I need.
super surprise thank you so much solved my problem
Thank. Very good 👍👍👍👍👍👍
Thats awesome thanks
great video as always, what about this: users->groupBy(x) // 5 groups
How to count groupBy elements?
Impossible to answer without exact example: grouping may happen with raw query, with eloquent, with collections, depending on the situation.
🔥
Hi sir i need code for a project i will pay u money for that
you r amazing.. do you have vid laravel websocket.. sory out of topic.. 😅😅
No, and that's why: twitter.com/PovilasKorop/status/1470640480593801216
@@LaravelDaily great.. thanks
Male/Female/Others
sir i want simple senario please give me
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.
PHPStorm does that for me automatically, these are hints, not the code.
why female relation repeat the code? I think better return $this->users()->where('gender','female');
Also possible, yes.
I'd call `where` off of the existing `users()` method just to prevent that duplication
public function users_male(): HasMany {return $this->users()->where(...);}