Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

tumas's avatar
Level 1

empty paginate if query with addBinding

I have Eloquent query with joins and conditions. The problem is that with this line, my query works weird:

$query->addSelect(DB::raw("IF(news.user_id= ? , 1, 0) as edit"))->addBinding($userId);
$query->get();               // returns collection of 27 items
$query->paginate(15);        // returns empty collection
$query->simplePaginate(15);  // returns collection of 15 items

can someone explain why this is happening with paginate()? Any solutions to get correctly paginate()?

0 likes
1 reply
tumas's avatar
tumas
OP
Best Answer
Level 1

found a solution.

->addBinding($userId, 'select')

Please or to participate in this conversation.