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


`

Top comments (2)

Collapse
 
jjlabajo profile image
JJ Labajo

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

Collapse
 
msbshabi profile image
Shabeer Ahammed

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

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More