I want to do a whereIn with a closure. Is this possible?
Normally, you would go and create it like this
return User::whereIn('id', [1, 2, 3])
->whereLang($channel)
->get();
But, what I wanted to do, is to do it with a closure - if possible. I have a database field, which has ids of users as a string (The table design is not mine, so I can't change it currently and have to work with it);
So I tried to do it like this
return User::whereIn('id', function () {
return FooBar::whereFooId('u' . $user->id)->get(['users'])->toArray();
})
->whereLang($lang)
->get();
However, when doing that, I'm getting the error
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 1096 No tables used'
I mean, in the database table I have the string with the ids stored like 1, 2, 3, 4
, so I would just need to do an explode(', ', $ids);
. This would solve my problem, when I do it in two steps, I was just wondering if I can do it in one, with the closure. And if so, how?