0

I'm trying to get data from a MySQL database into a blade file using eloquent buI'mim getting the following error:

Property [tournament_wins] does not exist on this collection instance. (View: C:\xamps\htdocs\lara_crud\resources\views\profile.blade.php

Heres the code from the controller :

 public function profile(){

        $statistics = UserStats::all();
        // return view('home')->with('user',$user);
        return view('profile')->with('statistics',$statistics);

    }

Heres a snippet of the code in the blade file :

                <div class = "col-md-8"> 


                     <div class = "col-md-8">

                     <ul class = "list-group" id = "listGroup">

                        <h1 class ="text-center"><span class="badge badge-pill badge-default">Your Profile Details</span>
                        <br>
                        <br>
                        <li class ="list-group-item text-center well wow zoomIn" id = "myList"><h2><span class="badge badge-pill badge-success"></span>{{$statistics->tournament_wins}}</h2><span></li>
                    </ul>

                </div>

           </div>
Jignesh Joisar
  • 13,720
  • 5
  • 57
  • 57
  • Possible duplicate of [Property \[id\] does not exist on this collection instance](https://stackoverflow.com/questions/43320223/property-id-does-not-exist-on-this-collection-instance) – dparoli Feb 22 '19 at 11:14
  • Possible duplicate of [Property \[title\] does not exist on this collection instance](https://stackoverflow.com/questions/41366092/property-title-does-not-exist-on-this-collection-instance) – Xitish Feb 22 '19 at 11:16

4 Answers4

2

@foreach($statistics as $statistic) {{ $statistic->tournament_wins }} @endforeach

To list multiple data on collection you have to loop over data.

Hope this helps :)

Maulik Shah
  • 1,040
  • 1
  • 7
  • 17
0

Your statistics is a collection of items, it is not only one item on which you can call a certain field, so you need to iterate over the statistics and show details for each, for example:

@foreach($statistics as $stat)
<li class ="list-group-item text-center well wow zoomIn" id = "myList">
<h2>
<span class="badge badge-pill badge-success"></span>
{{$stat->tournament_wins}}</h2><span>
</li>
@endforeach
nakov
  • 13,938
  • 12
  • 60
  • 110
0

your $statistics variable is an array, so you can't access to tournament_wins in this way.

you can use @foreach to iterate over $statistics, or you can access to the first item in the $statistics by typing $statistics[0].tournament_wins

boudlal
  • 82
  • 5
-1

Please paste first in the result of $statistics in the function profile add just before the return view... :

dd($statistics);

This show how this look-a-like. :) Before iterate with a foreach you need to show how the query result is build.

In Laravel dd is your friend ;)

Alpy
  • 759
  • 6
  • 9