Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

bcoder72's avatar

Parameter other db in query

i have problem for query in laravel. i have query like this in controller

$idbil = Msmpn::where('ID BILL','=', $request->idbil)->get();

when i input the data idbil it showing DB data and i want to make other query with parameter in data $idbil its like this

$pajak = Mskomap::select('SKTPOT')->where('KOMAP','=', $idbil->AKUN)->get();

and it showed

Property [AKUN] does not exist on this collection instance.

Anyone can solve this? sorry my english is not good

0 likes
4 replies
vitalyerofeev's avatar

Method ->get returns a collection of results.

If you want to get a single record from database - try to use ->first method

$idbil = Msmpn::where('ID BILL','=', $request->idbil)->first();
$pajak = Mskomap::select('SKTPOT')->where('KOMAP','=', $idbil->AKUN)->first();
bcoder72's avatar

@vitaly-erofeev like whe i visit the page it show

Attempt to read property "AKUN" on null

vitalyerofeev's avatar

@bcoder72 i think, that in DB does't exist the record with specific ID BILL, you can check it:

$idbil = Msmpn::where('ID BILL','=', $request->idbil)->first();
if (!$idbil) {
	// $idbil doesn't exists
	return false;
}

$pajak = Mskomap::select('SKTPOT')->where('KOMAP','=', $idbil->AKUN)->first();

Please or to participate in this conversation.