Home > Net >  Property [Total_Sayur] does not exist on this collection instance
Property [Total_Sayur] does not exist on this collection instance

Time:08-29

how to display or call value in array in laravel blade view ?

I already have the data that appears in the image below:

enter image description here

I still don't understand how to call the data in the :

@currency($laporan->Total_Sayur)

I'm tired of trying it in various ways and it always appears another error message. Please help me

MyController

public function index()
{
    $users = User::count();
    $kelompok = Kelompok::count();
    $anggota = Anggota::count();

    $laporan = Anggota::select('kecamatan', Produk::raw('avg(total_sayur) as Total_Sayur, avg(total_buah) as Total_Buah,avg(total_ikan) as Total_Ikan, avg(total_ternak) as Total_Ternak'))
        ->leftjoin('produk', 'produk.anggota_id', '=', 'anggota.id')
        ->where('kecamatan', '=', 'Ngajum')
        ->GroupBy('kecamatan')
        ->get();

    // return $laporan;

    return view('Dashboard.index', compact('users', 'kelompok', 'anggota', 'laporan'));
}

View

<div >
        <div >
            <!-- small box -->
            <div >
                <div >
                    <h3>@currency($laporan->Total_Sayur)</h3>

                    <p>TOTAl KEMANFAATAN</p>
                </div>
                <div >
                    <i ></i>
                </div>
                <a href="#" >More info <i ></i></a>
            </div>
        </div>

CodePudding user response:

Your solution start from here....

<div >

    <div >

        @foreach($laporan as $item)

            <!-- small box -->

            <div >

                <div >

                    <h3>@currency($item->Total_Sayur)</h3>

                    <p>TOTAl KEMANFAATAN</p>

                </div>

                <div >

                    <i ></i>

                </div>

                <a href="#" >More info <i ></i></a>

            </div>

        @endforeach

    </div>

</div>
  • Related