mercredi 29 mars 2017

Laravel Query Builder Sub-Queries - orderBy, groupBy

How can I convert the below query to query builder format in Laravel 5.3:

$query =   "SELECT *
    FROM (
        SELECT * FROM $table1
        WHERE msgNew=1
        ORDER BY msgDate DESC
    ) x
GROUP BY msgGroup
ORDER BY msgDate DESC
LIMIT 0, 10";

$results = DB::select($query);

Looking to convert it to:

$results = DB::table($table1)
    ->orderBy('msgDate', 'DESC')
    ->.....etc....
    ->groupBy('msgGroup')
    ->.....etc....
    ->get();



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire