Skip to content
This repository was archived by the owner on Jul 16, 2021. It is now read-only.
This repository was archived by the owner on Jul 16, 2021. It is now read-only.

Define a common interface for Query\Builder and Eloquent\Builder #987

@Patryk27

Description

@Patryk27

Illuminate\Database\Query\Builder and Illuminate\Database\Eloquent\Builder share a few common methods, namely: where, whereIn etc.

I think it could be useful if both classes implemented a common interface (named, say, QueryBuilderInterface), because:

  1. They actually do have common methods that do the same, thus interface could be used to ensure these both classes do not diverge on the common methods.

  2. It could be useful in cases like this one:

$someConnection->where(function(QueryBuilderInterface $db) {
  $db->where(...);
});

Right now one must either skip the type-hinting or do the type-hinting depending on the actually used builder, which is kind of unnecessary, since they both share the same methods we want to use (it also makes it harder/impossible to create re-usable callbacks, for what it's worth, if someone wanted to use exact function in both the Query & Eloquent builder).

I've prepared a minimal patch depicting my idea - I think eventually we should refactor at least all the *where* methods and think what to do with the rest.

https://github.com/Patryk27/framework/commit/e76cafb136c2d01028e6220a443a770594d5218f

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions