0

I have a mySql query that I need to convert using Eloquent(recommended) if possible. Here is my query:

SELECT * FROM  
( SELECT `uid`, `revision` FROM `tasks` ORDER BY `revision` DESC)  
x GROUP by uid

In my Project model I have the following:

$this->hasMany('\App\Task', 'project_id');

And now, How do I convert the sql query above using eloquent. Any help is appreciated.

Cheers all.

Dimitrov
  • 1
  • 1

1 Answers1

0

I found the solution. There is DB::select in laravel which is essential in this case.
Here is the solution:

$sub = 'SELECT * FROM `tasks` ORDER BY `revision` DESC';
                $results = DB::select(
                        DB::raw('select * from (' . $sub . ') x GROUP by uid')
                );
Dimitrov
  • 1
  • 1