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 - Хобби
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? ..
Hi sir i need code for a project i will pay u money for that
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.
I'd call `where` off of the existing `users()` method just to prevent that duplication
public function users_male(): HasMany {return $this->users()->where(...);}
why female relation repeat the code? I think better return $this->users()->where('gender','female');
Also possible, yes.
Thank you for going the extra mile and showcasing the various posibilities how to implement such a feature, and explaining the recommendations.
you always surprise us with a new useful tip. thank you.😊
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.
super surprise thank you so much solved my problem
Thanks for making this video
Thats awesome thanks
Splendid again. Thanks .
Excellent Explanation
Thank. Very good 👍👍👍👍👍👍
sir i want simple senario please give me
Male/Female/Others
Thank you, just what I need.
🔥
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.
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