json - Laravel 5.1 Eloquent collection not returning correct results -
i have eloquent collection {{ $questions }}
, when output inside blade template following results:
[{"question_num":0,"survey_id":2,"question_text":"test","expected_answer":1}, {"question_num":1,"survey_id":2,"question_text":"test","expected_answer":1}]
as can see there 2 objects. when apply filter {{ $questions->where('question_num','=', 0) }}
, following results correct:
[{"question_num":0,"survey_id":2,"question_text":"test","expected_answer":1}]
but when apply following filter {{ $questions->where('question_num','=', 1) }}
, empty result, why that, when collection has question_num value of 1?
[]
i've been scratching head day this!
the problem here use operator, here collection signature where
method is:
where( string $key, mixed $value, bool $strict = true)
so in both cases, should use:
{{ $questions->where('question_num', 0) }}
and
{{ $questions->where('question_num', 1) }}
to result expect
Comments
Post a Comment