Azzario Razy Azzario Razy -3 years ago 140
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.


public function index()
$absen = Absen::groupBy(raw('DATE(created_at)'))
->orderBy('created_at', 'DESC')
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


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')
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download