我一直在尝试从表“rates”中获取价格数据并将其存储在另一个表“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();
但是,我收到一条错误,指出检索的值不是 double 据类型:{“price”:80}。因此,我尝试将 first(['rates.price']);
更改为 value('rates.price')
但它存储为 null。
那么,为什么 {"price":80} 会变成 null 以及如何获取 80 的值?
最佳答案
你可以像这样使用select
方法在这里或直接获取
直接获取对象值 ->first()->price
而不是 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();
关于database - Laravel 不从数据库中检索双值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54604215/