Azzario Razy Azzario Razy - 1 year ago 57
PHP Question

query raw inside groupBy in larave 5.2

i have a problem with my query when im trying to group by Date(timestamp) in my laravel project, lets see my code.


[email protected]


public function index()
{
$absen = Absen::groupBy(raw('DATE(created_at)'))
->orderBy('created_at', 'DESC')
->get();
return view('rekap.index')->with('data', $absen);
}


in my sql syntax is work perfectly

SELECT * FROM absen GROUP BY DATE(created_at) DESC


how can i fix this, thanks

Edit:

The Error is


Call to undefined function App\Http\Controllers\raw()

Answer Source

you can try something like this

           $absen = Absen::groupBy(\DB::raw('DATE(created_at)'))
            ->orderBy('created_at', 'DESC')
            ->get();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download