I try to do a query with 2 where clauses, but I get a bad response, not sure why.
$history = AnswerHistory::where('question_id', '=', $id)
->where(function ($query) {
$query->where('answer_type', '!=', "skipped");
})
->get();
For a specific $id
in database I have 5 rows, 4 with answer_type = 'skipped
, but the 5-one is NULL
.
My response is null with this code, if I remove second where I get 5 items that includes "skipped"
answers.
Wanted response is 1 row, where answer_type != 'skipped'
.
PS. I also tried the answer from here.
The Problem is, a varchar that is null
is null
and not a varchar with a value. So it can not be checked with =
or !=
'string'. So you have to check if answer_type
is != skipped or null
$history = AnswerHistory::where('question_id', '=', $id)
->where(function ($query) {
$query->where('answer_type', '!=', "skipped")
->orWhereNull('answer_type');
})
->get();
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加