我已在查询中加入表,但我需要验证该表中列的值,它会返回
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'on' in 'on clause'
$interests = DB::table('projects')
->where('projects.published', 'y')
->whereDate('projects.created_at', Carbon::now()->subDay())
->join('project_tag', 'project_tag.project_id', '=', 'projects.id') //get project tags
->join('mailings', 'mailings.interests', '=', 'on') //get mailing lists with on value in interests column
->join('users', 'users.id', '=', 'mailings.user_id') //get mailing users
->join('user_interests', 'user_interests.user_id', '=', 'users.id') //get mailing users intrests (same as tags in projects)
->select('projects.*', 'users.*')
->get();
我的问题在这一行
->join('mailings', 'mailings.interests', '=', 'on')
我只想加入mailings
列值设置为intrests
的{{1}}
有什么主意吗?
我将发布行更改为:
on
现在返回结果,但是输出数据重复且不完整。这是我在->join('mailings', function ($join) {
$join->where('mailings.interests', '=', 'on');
})
dd
要明确 lluminate\Support\Collection {#819
#items: array:6 [
0 => {#824
+"title": "test 1"
+"slug": "test-1"
+"budget": 23454235.0
+"name": "Diana Bosco"
+"email": "arunolfsson@example.net
}
1 => {#827
+"title": "test 1"
+"slug": "test-1"
+"budget": 23454235.0
+"name": "Diana Bosco"
+"email": "arunolfsson@example.net
}
2 => {#820
+"title": "test 1"
+"slug": "test-1"
+"budget": 23454235.0
+"name": "admin"
+"email": "admin@admin.com"
}
3 => {#826
+"title": "test 1"
+"slug": "test-1"
+"budget": 23454235.0
+"name": "admin"
+"email": "admin@admin.com"
}
4 => {#823
+"title": "test 1"
+"slug": "test-1"
+"budget": 23454235.0
+"name": "Aurelia Treutel I"
+"email": "korey13@example.net"
}
5 => {#825
+"title": "test 1"
+"slug": "test-1"
+"budget": 23454235.0
+"name": "Aurelia Treutel I"
+"email": "korey13@example.net"
}
]
答案 0 :(得分:0)
使用'sep 28 2017 abcd'
通过FK引用联接->join()
表,就像您对其他表所做的一样,然后将mailings
子句更改为条件数组:
where
答案 1 :(得分:0)
将过滤器应用为
$interests = DB::table('projects')
->where('projects.published', 'y')
->whereDate('projects.created_at', Carbon::now()->subDay())
->join('project_tag', 'project_tag.project_id', '=', 'projects.id') //get project tags
// the filter
->where('mailings.interests', 'on')
->join('users', 'users.id', '=', 'mailings.user_id') //get mailing users
->join('user_interests', 'user_interests.user_id', '=', 'users.id') //get mailing users intrests (same as tags in projects)
->select('projects.*', 'users.*')
->get();