Ibe
102
2
Laravel

How do I count items in show page with relationships

Posted 2 months ago by Ibe

Hi there, im having a problem with the counts and I really don't know how to solve it.. So I would like to count all the items (commemorative) in the 'Jointly show' page. The commemoratives belong to a jointly, they are linked by id. Does anyone know how I can solve this?

PagesController:

  public function getJointlyShow($name){
    $jointlies = Jointly::whereName($name)->first();
    $count = Commemorative::count();
  
    return view('pages/jointly-show')->withJointlies($jointlies)->with('count', $count);;
  }

jointly-show.blade.php:

    {{ $count }}

    @foreach ($jointlies->commemoratives->sortBy('country:name') as $commemoratives)

            <span>{{$commemoratives->title}}</span>

    @endforeach

Thanks!!

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

Reply to

Use Markdown with GitHub-flavored code blocks.