JavaScript
x
$dean_ids = Auth::user()->dean_id; // "9,11"
$subjects = Subject::whereIn('dean_id', [$dean_ids])->select('id')->get();
returns only data for “9” but when i trying like this:
JavaScript
$subjects = Subject::whereIn('dean_id', [9,11])->select('id')->get();
//it returns all data that what i want.
how can i fix it?
Advertisement
Answer
As I see, this line $dean_ids = Auth::user()->dean_id;
returns a comma-separated string. So when you make $dean_ids
array by using [$dean_ids]
it actually makes an array like:
JavaScript
array(
'9,11'
)
Instead of
JavaScript
array(
9,
11
)
There is only one value inside the array. So what you can do just use explode
for splitting the string by using a comma and it also returns an array.
You can try this:
JavaScript
$subjects = Subject::whereIn('dean_id', explode(',', $dean_ids))->select('id')->get();