我面临一个问题,我想从数据库中获取start_date
,但是我仅获得空值,它没有显示值。
请检查此图片以更好地了解:https://imgur.com/eCrGeTW
这是代码:
$data = \DB::table("subscriptions")
->select("subscriptions.*",
\DB::raw("(SELECT subscriptions.start_date FROM subscriptions
WHERE subscriptions.business_id = $business_id
) as date"))
->orderBy('subscriptions.start_date', 'desc')
->get();
dd($data);
最佳答案
尝试这个
$data = DB::table("subscriptions")->where('business_id',$business_id)->orderBy('start_date', 'desc')->get();
dd($data);
如果只需要
start_date
,则编写此代码 $data = DB::table("subscriptions")->where('business_id',$business_id)->orderBy('start_date', 'desc')->pluck('start_date');
dd($data);
要么
$data = DB::table('subscriptions')->select('start_date')->where('business_id',$business_id)->orderBy('start_date', 'desc')->get();