简体   繁体   中英

How to get price from mysql using laravel

I am trying to get the adult and child price form a table where id is 3. How can I do this using Laravel?

------------------
id adult child
------------------
2   100  50
3   200  100

I am not sure how to continue after this $price = DB::table('tours')->where('id', 3)

I would appreciate any help.

first() returns the first record ,looks like you need single model to return

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

If you have multiple model

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

If you just need price , use pluck

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

EDIT Looks like you edit your question , so I need to edit my answer

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM