DEV Community

mostafalaravel
mostafalaravel

Posted on

How to convert this sql query to Eloquent ?

How to convert this sql query to Eloquent ?

SELECT user_id, company_id, MAX(date) date 
FROM careers 
GROUP BY user_id, comapany_id;
Enter fullscreen mode Exit fullscreen mode


`

Oldest comments (2)

Collapse
 
msbshabi profile image
Shabeer Ahammed

$careers = Career::selectRaw('user_id, company_id, MAX(date) as date')->groupBy(['user_id','comapany_id'])->get();

Collapse
 
jjlabajo profile image
JJ Labajo

I just made a tool just for this. You can use it for free:
jjlabajo.github.io/SQLtoEloquent/