Do you use soft deletes on your model? Having deleted_at column in your table, Eloquent will automatically ignore those rows, unless you add withTrashed().
@laracoft you said you are using eloquent. If that's right then it should be Model::withTrashed()->... if you use the query builder then you should just add ->orWhereNotNull('deleted_at') so in your SQL script in order to get the same results you should add the same check where deleted_at is null or is not null.
@laracoft no it does not. You can run ->toSql() on that and inspect why is it different then your custom SQL query. You are not sharing any code, so I don't know how to help.
I would like to, but the raw query constructed by the query builder is 60+ lines long and involves multiple tables. It will almost certainly raise more questions than answers.
What puzzles me is why the raw query yields my desired output, but gives the wrong output when executed via code.
Let me try to dig a bit further and simplify the query if I can.