0

I've an error like Trying to get property of non-object, I use var_dump and realize that I've array not object but idk how to access

public function ptkp($id){
    $halaman="tindaklayanan";
    $keluhan = keluhan::findOrFail($id);

    $tindak = DB::table('tindakans')
    ->join('keluhans','keluhans.id','=','tindakans.id_keluhan')
    ->select(DB::raw('tindakans.id, id_keluhan, perbaikan_sementara, revisi_dokumen, target_verifikasi, ttd_tanggung1,
    ttd_tanggung2'))->get();

    $analisa = DB::table('analisas')
    ->join('tindakans','tindakans.id','=','analisas.id_tindakan')
    ->join('keluhans','keluhans.id','=','tindakans.id_keluhan')
    ->select(DB::raw('id_tindakan, analisa, tindakan, pic, tanggal_pelaksanaan'))->get();

    return view('Laporan.ptkp',compact('keluhan','tindak','analisa','halaman'));
    //$pdf = \PDF::loadView('laporan.ptkp', compact('keluhan','tindak','analisa','halaman'));
    //return $pdf->stream();
}

Look at $tindak when I use var_dump the result is array, in View I try to access using <?php echo $tindak->perbaikan_sementara ?> but error.

2 Answers 2

1

Since you are in Laravel, I assume you use a blade templating engine, so you can try this in the view to access property of object :

{{ $tindak->perbaikan_sementara }}

Or if it's an array of objects :

@foreach ($tindak as $example)
   {{ $example->perbaikan_sementara }}
@endforeach
Sign up to request clarification or add additional context in comments.

Comments

1

if you really have an array it's in your Laporan.ptkp (better use laporan.blade.php instead)

@foreach ($tindak as $item) {{ $item['perbaikan_sementara'] }} @endforeach

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.