2017-08-14 132 views
0

我有我的查詢中的一個問題是不是在我laravel 5.2CURDATE()查詢中laravel不工作5.2

AbsenController工作CURDATE() @指數

$now = time(); 
$absen = Absen::with('siswa')->where('level', '=', 'Siswa', 'AND', 
'created_at', '<=', 'CURDATE()')->get(); 
return view('absen.index')->with('data', $absen); 

,這是紀錄我的Absen表

Absen Table

+0

'query not working' ... _what_不工作?你能從你的Laravel代碼執行_any_查詢嗎? –

回答

0

我不熟悉你的where sytnax。嘗試包括每兩個條件在WHERE條款單獨條款:由

$absen = Absen::with('siswa') 
    ->where('level', '=', 'Siswa') 
    ->whereRaw('created_at <= curdate()') 
    ->get(); 

的條件是AND組合在一起:

$absen = Absen::with('siswa') 
    ->where('level', '=', 'Siswa') 
    ->where('created_at', '<=', DB::raw('curdate()')) 
    ->get(); 

作爲一種變型,你也可以使用whereRaw()處理涉及CURDATE()條件默認的,這是你在兩個條件之間的關係。如果要在WHERE條款中將OR條件合併,請查看orWhere()

+0

仍然沒有工作:( –

+0

@AzzarioRazy你應該詳細說明'不工作'實際上是什麼意思。也許你的連接有問題。你能否從你的Laravel代碼執行_any_查詢?我的回答是正確的,或者至少應該是,假設你沒有其他問題而不是糾正的問題。 –

0
$now = time(); 
$absen = Absen::with('siswa')->where('level', 'Siswa')->where('created_at','<=',\Carbon\Carbon::now())->get(); 
return view('absen.index')->with('data', $absen);