Laravel数据库仅存储值而不是数组

时间:2017-03-24 14:24:46

标签: laravel laravel-5 laravel-5.2 laravel-5.1 laravel-5.3

$visitorphonenumber=DB::select('select phonenumber from visitortable where email=?',[Auth::user()->email]);

$booking=new bookingmodel();
$booking->visitorphonenumber=$visitorphonenumber;

这会将[{"phonenumber":"9874589608"}]之类的值存储在数据库中,但我只想存储9874589608

2 个答案:

答案 0 :(得分:2)

我会在上面添加一些糖,就像

一样
$visitorphonenumber->first()->phonenumber;

答案 1 :(得分:1)

尝试

$visitorphonenumber=DB::select('select phonenumber from visitortable where email=?',[Auth::user()->email]);

$singlePhoneNumber=$visitorphonenumber->first();