-1
我試着寫在模型局部範圍自定義查詢:如何在模型Laravel中編寫自定義查詢?
public function scopeLastSync($query)
{
return DB::table('clients')
->select(DB::raw(
"select COUNT(*) as total, (SELECT created_at FROM clients ORDER BY created_at DESC LIMIT 1)"
))->get();
}
但它不工作。如何使用easy:DB :: query(「原生SQL查詢」)? 我想:
return DB::raw("select COUNT(*) as total, (SELECT created_at AS date_modify FROM clients ORDER BY created_at DESC LIMIT 1)");