Laravel 4 查询构建器 - 未找到非空列
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21440430/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel 4 query builder - not null column not found
提问by Patrick Cauley
Route::get('/test', function(){
return DB::table('table')->where_not_null('column')->get();
});
In Laravel 4 I have the following route, obviously with table and column replaced. I had it in the controller but it wasn't working, so I moved it to a test route.
在 Laravel 4 中,我有以下路线,显然替换了表和列。我把它放在控制器中,但它不起作用,所以我把它移到了一条测试路线上。
The error I am getting is:
我得到的错误是:
SQLSTATE[42S22]: Column not found: 1054 Unknown column '_not_null' in 'where clause' (SQL: select * from `table` where `_not_null` = column)
https://tower.la.utexas.edu/docs/database/fluent#where
https://tower.la.utexas.edu/docs/database/fluent#where
Documentation says:
文档说:
return DB::table('table')->where_null('column')->get();
回答by The Alpha
It should be
它应该是
return DB::table('table')->whereNull('column')->get();
Or
或者
return DB::table('table')->whereNotNull('column')->get();
You have used where_not_null
.This is the right reference.
您已经使用过where_not_null
。这是正确的参考。
回答by lukaserat
See the proper writing for that: http://laravel.com/docs/queries#selects
请参阅正确的写作:http: //laravel.com/docs/queries#selects
DB::table('table')->whereNotNull('column')->get();
回答by Patrick Cauley
The documentation states that following the table declaration you should put the query builder information, where_null, where_not_null, where_in.
该文档指出,在表声明之后,您应该放置查询构建器信息 where_null、where_not_null、where_in。
However that doesn't work. I'm not sure why, it makes no sense, and is frustrating. However, this does work.
然而这行不通。我不知道为什么,这毫无意义,而且令人沮丧。但是,这确实有效。
return DB::table('user')->whereuserName('not_null')->get();
By placing the column name where the documentation says to put the query, and the query where the documentation says to put the column you are able to execute your query. To note, camel case is converted to snake case in the query, so the column has to be named user_name.
通过将列名放置在文档所说的放置查询的位置,以及文档所说的放置列的查询,您就可以执行查询。需要注意的是,在查询中驼峰大小写转换为蛇大小写,因此该列必须命名为 user_name。
I am posting this because I attempted googling it and was not able to find anything.
我发布这个是因为我试图用谷歌搜索它并且找不到任何东西。