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
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();
@vitaly-erofeev thank you its working, but its make another problem
@vitaly-erofeev like whe i visit the page it show
Attempt to read property "AKUN" on null
@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.