gpt4 book ai didi

mysql - 如何使用laravel从mysql获取价格

转载 作者:行者123 更新时间:2023-11-29 10:50:53 26 4
gpt4 key购买 nike

我正在尝试从 id 为 3 的表中获取成人和 child 价格。我如何使用 Laravel 执行此操作?

------------------
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();

如果你只需要价格,请使用 pluck

$price = DB::table('tours')->where('id', 3)->pluck('price');

编辑看来您编辑了您的问题,所以我需要编辑我的答案

$price = DB::table('tours')->where('id', 3)->select('adult', 'child')->first();

关于mysql - 如何使用laravel从mysql获取价格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43748363/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com