Fix bug causing wrong index to be returned

This commit is contained in:
Toby Zerner 2015-02-25 15:36:17 +10:30
parent 9ea482254c
commit 3c53e512de
2 changed files with 5 additions and 3 deletions

View File

@ -1,6 +1,5 @@
<?php namespace Flarum\Api\Actions\Posts;
use Flarum\Core\Repositories\PostRepositoryInterface;
use Flarum\Core\Models\User;
use Flarum\Api\Actions\ApiParams;

View File

@ -96,8 +96,11 @@ class EloquentPostRepository implements PostRepositoryInterface
->from('posts')
->where('discussion_id', $discussionId)
->whereNotNull('number')
->orderByRaw('ABS(CAST(number AS SIGNED) - ?)', [$number])
->take(1);
->take(1)
// We don't add $number as a binding because for some
// reason doing so makes the bindings go out of order.
->orderByRaw('ABS(CAST(number AS SIGNED) - '.(int) $number.')')
});
return $this->scopeVisibleForUser($query, $user)->count();