I have this SQL query:
SELECT *
FROM posts
RIGHT JOIN files ON posts.id = files.fileable_id
GROUP BY posts.id
HAVING posts.user_id = 3125
It works, but I need to convert it to Laravel eloquent I tried this code
$postsHaveFileCount = DB::table('posts')
->rightJoin('files', 'posts.id', '=', 'files.fileable_id')
->groupBy('posts.id')
->having('posts.user_id', '=', $user->id)
->get()->count();
echo $postsHaveFileCount;
But i have this error
(2/2) QueryException SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #17 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'staff.files.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by (SQL: select * from
posts
right joinfiles
onposts
.id
=files
.fileable_id
group byposts
.id
havingposts
.user_id
= 3125)
I will be thanks for all to help me to solve the problem, thanks in advance.