gregory
gregory

Reputation: 1140

Find model by a string

I'm having a hard time finding the problem in this repository method:

public function findByString($string)
{
        return User::where('string', $string)->get();
}

It generates the correct SQL statement which I can run in Sequel Pro returning the right result.

However, when this method is called in Laravel (4.2), the result is always empty:

$this->user->findByString('something');

On the other side

$this->user->findOrFail(1);

Always returns the correct model.

Any ideas what could be wrong?

Upvotes: 0

Views: 89

Answers (1)

RobbieP
RobbieP

Reputation: 698

return User::where('string', $string)->get(); 

Will return a collection that you can iterate through.

If you want the first instance back as an Eloquent model you can do this:

return User::where('string', $string)->first();

Upvotes: 3

Related Questions