我是新來的laravel,我想使用多個where子句並使用curdate()。CURDATE()與laravel 5
這是一個例子:
$data = DB::table('toutcome')->where('date', '>=', curdate())->where('Status', '=', 'A')->count('AppID');
return view('home', compact('data'));
它不工作。
我是新來的laravel,我想使用多個where子句並使用curdate()。CURDATE()與laravel 5
這是一個例子:
$data = DB::table('toutcome')->where('date', '>=', curdate())->where('Status', '=', 'A')->count('AppID');
return view('home', compact('data'));
它不工作。
因此,與在評論答案一起:
public function index()
{
// First query with DB::raw() variant
$data = DB::table('toutcome')
->where('date', '>=', DB::raw('curdate()'))
->where('Status', '=', 'A')
->count('AppID');
// Second query with Carbon variant
$data2 = DB::table('toutcome')
->where('date', '>=', Carbon::now())
->where('Status', '=', 'A')
->count('AppID');
// Third query with '@Sunny' whereRaw variant
$data3 = DB::table('toutcome')
->whereRaw('date >= curdate()')
->where('Status', '=', 'A')
->count('AppID');
return view('home', compact('data','data2','data3'));
}
我不緊湊的()個人,所以我會寫一個大風扇:
return view('home', ['data'=>&$data,'data2'=>&$data2,'data3'=>&$data3])
雖然個人(如果你想閱讀更進一步)閱讀在ViewComposers:
變化 where('date', '>=', curdate())
到 whereRaw('date >= curdate()')
其他可能性:'在哪裏( '日', '> =',碳::現在())'和'在哪裏( 'date','> =',DB :: raw('curdate()'))' –
謝謝,這也教會了我一件事! :) –
@SunnyRGupta,謝謝你,謝謝Justion,你可以看看更新的問題。 – Matt
嘗試請'andWhere()'的第二個條件 –