0

Hi I'm currently developing a voting system using laravel. I want to attach a member count in each party. This is my code

$partylist = Partylist:all();

I want to achieve this on my blade :

{{$partylist->members}}
1
  • 2
    show your party and members model Commented Oct 26, 2018 at 7:52

3 Answers 3

2

try this:

{{$partylist->count()}}

or if you want to count the members:

{{$partylist->members->count()}} 

or

{{count($partylist->members)}}

Sign up to request clarification or add additional context in comments.

Comments

0

If your $partylist->members is an array, use sizeof() function of PHP to get size of this. So you can use in blade as follows:

{{sizeof($partylist->members)}}

Hope it can help you

Comments

0

There are two ways to do it :

$partylist = Partylist::all();

foreach ($partylist as $pl) {
    echo $pl->members()->count();
}

Or counting related model

$partylist = Partylist::withCount('members')->all();

foreach ($partylist as $pl) {
    echo $pl->members_count;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.