Hi can ask some help on this raw query it has no output,
$userproj_id = UserProject::select('projid')->where('user_id', $id)->get()->toArray();
$flattenid = array_flatten($userproj_id);
foreach ($flattenid as $projid) {
$projidarr [] = $projid;
}
$users = DB::select('select * from project where projid in ( ? ) and user_id = 3 ', $projidarr );
but if I will manually do like this, it works fine..
$users = DB::select('select * from project where projid in ( ? ) and user_id = 3 ', ['12345']);
but when I do this manually no output again.
$users = DB::select('select * from project where projid in ( ? ) and user_id = 3 ', ['12345','11111']);
Thank you in advance.
It's because in your bindings array, you have to many parameters - the SQL needs only one, and you are providing two. A proper parameter list would be [implode(',', [12345, 1111])] but in this case it would be a string and the result wouldn't be correct as well
What about this?
DB::table('project')
->whereIn('projid', [12345, 1111])
->where('user_id', '=', 3);
Raw Query:
$users = DB::select('select * from project where projid in ('. implode(',', $projidarr).') and user_id = 3 ');
and Laravel query:
DB::table('project')
->whereIn('projid', $projidarr)
->where('user_id', '=', 3);