我正在尝试使用Laravel 4中的where子句构建对我的数据库的调用.听起来很简单,但我收到一个没有意义的错误.此通话有效:
return MainContact::all();
Run Code Online (Sandbox Code Playgroud)
当我查看该页面时,我得到了我的数据的JSON表示,包含了我所有的数据,就像你期望的那样.它包括:
... "flag":1 ...
Run Code Online (Sandbox Code Playgroud)
所以当我尝试这样做时,正如Laravel文档中所解释的那样:
return MainContact::where('flag', '=', '1');
Run Code Online (Sandbox Code Playgroud)
你会认为它会起作用,但事实并非如此.我已经尝试将数字作为字符串和整数,并且都不起作用.我收到此错误:
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
Run Code Online (Sandbox Code Playgroud)
Laravel 4中的where子句有什么变化吗?或者我不明白怎么做?
你有没有尝试过:
return MainContact::where('flag', '=', '1')->get();
Run Code Online (Sandbox Code Playgroud)
或更简单地说:
return MainContact::where_flag(1)->get();
Run Code Online (Sandbox Code Playgroud)