I tried to write custom query in model as local scope:
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();
}
But it does not work. How to use easy: DB::query("native SQL query")? I tried:
return DB::raw("select COUNT(*) as total, (SELECT created_at AS date_modify FROM clients ORDER BY created_at DESC LIMIT 1)");