Laravel 10 Multiple WithCount Same Relationship Example

Hello artisan,

In this tutorial, we will see how to create the same model multiple with count relationship with the same relationship. Sometimes you may need to create multiple withcount with the same relationship in Laravel. If you you do not know how to create a laravel multiple withcount same relationship then this example is for you.

I will share with you the source code of laravel 10 multiple withcount same relationship. Let's see the example code of laravel withcount same relationship.

Model::withCount(['relation as relation_one' => function ($query) {
        $query->where('type', 1);
    }, 'relation as relation_one' => function ($query) {
        $query->where('type', 2);


Read also: Call To A Member Function Map() On Array Laravel - (Solved)


Hope it can help you.