简体   繁体   English

Laravel 4查询生成器-未找到非空列

[英]Laravel 4 query builder - not null column not found

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. 在Laravel 4中,我有以下路线,显然是用表和列替换的。 I had it in the controller but it wasn't working, so I moved it to a test route. 我将其放在控制器中,但无法正常工作,因此将其移至测试路线。

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();

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 。这是正确的参考

请参阅相应的文章: http : //laravel.com/docs/queries#selects

DB::table('table')->whereNotNull('column')->get();

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. 我发布此邮件是因为我尝试对其进行谷歌搜索,但找不到任何东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM