Toni Perić
Toni Perić

Reputation: 512

Laravel Find and Where querying

Why does the following code return the exception "Call to a member function where() on a non-object"?

SomeModel::find( $id )->where('name', $name);

Upvotes: 0

Views: 426

Answers (1)

Antonio Carlos Ribeiro
Antonio Carlos Ribeiro

Reputation: 87719

Because

SomeModel::find( $id );

Returns a model, not a Query Builder instance, it's the end of the query.

You must do

SomeModel::where('name', $name)->where('somethingElse', '=', 'value')->first();

Upvotes: 3

Related Questions