I'm trying to build a call to my database with a where clause in Laravel 4. Sounds simple enough, but I'm getting an error that makes no sense. This call works:
return MainContact::all();
When I view that page, I get a JSON representation of my data, with all of my data, like you'd expect. It includes this:
... "flag":1 ...
So when I try to do this, as explained in the Laravel documentation:
return MainContact::where('flag', '=', '1');
you would think it would work, but it doesn't. I've tried the number as both a string and integer, and neither works. I get this error:
ErrorException: Catchable Fatal Error: Object of class
Illuminate\Database\Eloquent\Builder could not be converted to string in
/Users/universal/Sites/universalLaser/leads/vendor/symfony/http-foundation/Symfony/
Component/HttpFoundation/Response.php line 351
Has something changed with where clauses in Laravel 4? Or am I not understanding how to do them?
have you tried:
return MainContact::where('flag', '=', '1')->get();
or more simply:
return MainContact::where_flag(1)->get();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With