如何使用laravel从mysql获取价格
我试图从一张id为3的表格中得到成人和儿童的价格。我如何使用Laravel做到这一点如何使用laravel从mysql获取价格,mysql,database,laravel-5,Mysql,Database,Laravel 5,我试图从一张id为3的表格中得到成人和儿童的价格。我如何使用Laravel做到这一点 ------------------ id adult child ------------------ 2 100 50 3 200 100 我不知道在这之后如何继续 $price=DB::table('tours')->where('id',3) 如果有任何帮助,我将不胜感激。first()返回第一条记录,看起来您需要单个模型才能返回 $price = DB::table('tours')-&
------------------
id adult child
------------------
2 100 50
3 200 100
我不知道在这之后如何继续
$price=DB::table('tours')->where('id',3)
如果有任何帮助,我将不胜感激。first()返回第一条记录,看起来您需要单个模型才能返回
$price = DB::table('tours')->where('id', 3)->first();
如果你有多个模型
$price = DB::table('tours')->where('id', 3)->get();
如果你只需要价格,就用勇气
$price = DB::table('tours')->where('id', 3)->pluck('price');
编辑
看起来你编辑了你的问题,所以我需要编辑我的答案
$price = DB::table('tours')->where('id', 3)->select('adult', 'child')->first();
非常感谢你,所以我得拔两次。对于成人
DB::table('tours')->where('id',3)->pull('成人')
和儿童DB::table('tours')->where('id',3)->pull('child')
我是对的吗?我得到了一个类stdClass的错误对象无法转换为字符串。。当我使用->select('id','成人')->first()时
我想你的意思是成人
而不是名字
,但当我使用$price=DB::table('tours')->where('id',3)->pull('maduent')时,它就起作用了代码>$price=DB::table('tours')->where('id',3)->选择('成人','儿童')->first();当我执行此操作时,我得到一个类为illumb\Support\Collection的错误对象无法转换为intecho 2*$price
您知道原因吗?