【问题标题】:Laravel 5.1 whereNotNull with join not working (returning all data)Laravel 5.1 whereNotNull 与连接不起作用(返回所有数据)
【发布时间】:2015-07-13 16:04:54
【问题描述】:

我正在尝试选择列名为“review”的“用户”表中的所有非空列。

$applications = DB::table('users')
    ->join('applications', 'user.update_id', '=', 'applications.id')
    ->whereNotNull('users.review')
    ->select('user.id', 'user.rating', 'user.appid', 'user.review', 'applications.title', 'applications.price', 'applications.icon_uri')
    ->orderBy('user.id','asc')
    ->paginate(20);
$applications->setPath('');
return $applications;

但是返回的数据包括'user.review'空和非空的所有信息。

感觉whereNotNull()没有效果,也没有发现语句有错误。

我试着移动->whereNotNull('user.review')这条线的顶部和底部结果是一样的。

我什至尝试删除 select 和 orderBy 但返回相同的数据。

$applications = DB::table('users')
    ->join('applications', 'user.update_id', '=', 'applications.id')
    ->whereNotNull('users.review')
    ->paginate(20);
$applications->setPath('');
return $applications;

有没有办法让它工作?

【问题讨论】:

    标签: php mysql laravel-4 eloquent laravel-5


    【解决方案1】:

    如果你的表是users,你在表名中缺少一个s,你应该写

    ->whereNotNull('users.review')
    

    join 与字段 update_id 的情况相同,否则必须在 table 方法中更改表名

    【讨论】:

    • 不,这不是问题。我再次编辑了问题。
    • 数据库中的列真的有NULL值还是只是空的?
    • 它起作用了,唯一的问题是行是空的。数据库中不为空
    猜你喜欢
    • 2016-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多