3 years ago

Trying to get Count of a Model must return an object of type

Posted 3 years ago by jsrosas

Hi All, I am trying to get a count of all the model with a specific parameter. The model name is Member, inside the model I am declaring this function to get a count of all the other members that have a field that matches the id of the current Member.

public function refer(){
        $referCount = Member::where('referer_id', $this->vendorname)->count();
        return $referCount;

Then in blade I am trying to call it by using $member->refer in a @foreach loop. I get

Relationship method must return an object of type Does anyone have any ideas? If I do a dd($referCount) I get the desired value. Is there another way to get this result? This is for a dashboard and I'll need to do this kind of queries. So it will be

@foreach($members as $members)
<td>{{$member->first_name}} {{$member->first_name}}</td>

And so on I am just looking for a simpler way of doing this queries and being able to call them in blade in for a for each loop. Thank you in advance.

Please sign in or create an account to participate in this conversation.