I have the following code in my laravel project
$config = DB::table('custom_config')->where('item_id', 5);
$cost = [
'car_service_fee' => $config->where('managed_by', 1)->first()->service_fee,
'bike_service_fee' => $config->where('managed_by', 2)->first()->service_fee
];
My custom_config
table is as of below.
+---------+------------+-------------+
| item_id | managed_by | service_fee |
|---------+------------+-------------|
| 5 | 1 | 8.5 |
|---------+------------+-------------|
| 5 | 2 | 2.0 |
+---------+------------+-------------+
my car_service_fee
is fetching the result of 8.5
but my bike_service_fee
is returning null
on first()
The same code works if it is just like given below,
$cost = [
'car_service_fee' => DB::table('custom_config')->where('item_id', 5)->where('managed_by', 1)->first()->service_fee,
'bike_service_fee' => DB::table('custom_config')->where('item_id', 5)->where('managed_by', 2)->first()->service_fee
];
Is there any problem on back to back first()
method used on a query builder that is stored in a variable or something in laravel?
Thank you