我是新来的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()'的第二个条件 –