Petyor
Petyor

Reputation: 404

Chain eloquent query builder method to find()

Is there a way to chain an eloquent query builder method like where to method like find? For example:

Model::find($id)->where('slug', $slug);

The idea here is not to call where twice like this:

Model::where('id', $id)->where('slug', $slug);

Upvotes: 0

Views: 159

Answers (1)

N69S
N69S

Reputation: 17205

Yes, just reverse the order

Model::where('slug', $slug)->find($id);

but it doesnt make much sense since the id is unique by itself.

Upvotes: 6

Related Questions