framework: using orWhere on a soft delete model returns deleted items?

I’m having an issue using an eloquent query to search for my users.

$users = User::where('email', 'like', '%'.$search.'%')->orWhere('brid', 'like', '%'.$search.'%')->orderBy('brid', 'ASC')->paginate(5);

This is returning deleted and un-deleted users.

I am not using the withTrashed() function, so i should be just getting my un-deleted users in the result.

If i remove the orWhere() it then works correctly.

Is this something that can be fixed in Eloquent?

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Comments: 16 (7 by maintainers)

Most upvoted comments

While this is a logical result of the way the queries are built, the documentation is seriously misleading:

When querying a model that uses soft deletes, the “deleted” models will not be included in query results.

With automagical features like this, you kind of expect them to work as described. If they don’t, maybe it’s better to just explain the technical details of what they do.

I honestly don’t think this is a “bug”, but just a logical way SQL works. The “work-around” should be used to group the statements logically.