2

I have been trying to get price data from table 'rates' and store it in another table 'bookings'.

$duit =Booking::Join('rates', 'bookings.park_area','=', 'rates.areaid')
    ->where('bookings.user_id', '=', Auth::user()->userid)
    ->where('bookings.park_area','=',$bookings->park_area)
    ->where('bookings.semester','=',$bookings->semester)
    ->first(['rates.price']);  
$bookings->price=($duit);
    $bookings->save();

However, i get an error stating that the value retrieve is not of a double datatype: {"price":80}. So, I tried changing first(['rates.price']); to value('rates.price') but it stores as null.

So, why does {"price":80} become null and how to get the value of 80?

1
  • Try var_dump the $duit and check what it gives? Commented Feb 9, 2019 at 7:41

1 Answer 1

2

you can used like that use select method here or directly get

get object value directly ->first()->price instead or this -->first(['rates.price']);

$duit = Booking::Join('rates', 'bookings.park_area','=', 'rates.areaid')
    ->where('bookings.user_id', '=', Auth::user()->userid)
    ->where('bookings.park_area','=',$bookings->park_area)
    ->where('bookings.semester','=',$bookings->semester)
    ->select('rates.price')
    ->first()->price;  

$bookings->price = $duit;
$bookings->save();
Sign up to request clarification or add additional context in comments.

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.