rows = Campaign::with('limitations');
$rows->whereHas('limitations', function($q){
$q->where('country_id', '!=', Auth::user->countryId)->where('type', 'foo2');
});尽管有线
$q->where('country_id', '!=', Auth::user->countryId)我仍然有行有'foo‘在其中。我试过使用'<>‘和'!=’,但两者都不起作用。我的代码行有什么问题?或者这是一只猛禽虫?
更新:
如果我将代码更改为
$q->where('country_id', '!=', Auth::user->countryId)->where('type', '!=', 'foo2');我将得到不是‘foo2 2’的结果,但它不适用于Auth::user->country_id。
表结构:
Campaign id,has_limit
用户 id,countryId
Campaign_has_limitations id,campaign_id,country_id,类型
发布于 2015-09-10 05:29:31
试试这个:
$countryid = Auth::user->countryId;
rows = Campaign::whereHas('limitations', function($q) use ($countryid) {
$q->where('country_id', '!=', $countryid)
->where('type', '!=', 'foo2');
});https://stackoverflow.com/questions/32492442
复制相似问题