Skip to content
Advertisement

How to Use WhereIn Query in Laravel 8

Controller

    public function detail(Peserta $peserta)
    {
        // get konfirmasi_id
        $konfirmasi = KonfirmasiPembayaran::where('email',$peserta->email)->select('id')->get();

        $payments   = BankSettlement::whereIn('konfirmasi_id',array($konfirmasi->id))->get();
        // dd($payments);
        $tagihan    = Tagihan::where([['peserta_id', $peserta->id],['type', 3]])->first();
        return view('data.peserta.detail', ['data' => $peserta, 'payments' => $payments,'tagihan' => $tagihan]);
    }

I want to display data from BankSettlement based on konfirmasi_id. Here I try to use WhereIn Query like this, but still error “Property [id] does not exist on this collection instance.”.

konfirmasi variable

$konfirmasi has data like the image above.

What is the correct way to display data from BankSettlement based on konfirmasi_id ? Thankyou

Advertisement

Answer

Try this changes:

    $konfirmasi = KonfirmasiPembayaran::where('email',$peserta->email)->pluck('id')->toArray();

    $payments   = BankSettlement::whereIn('konfirmasi_id',$konfirmasi)->get();
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement