Add limit to budget #3150

This commit is contained in:
James Cole 2020-07-21 06:23:37 +02:00
parent 858158d886
commit 723696b971
No known key found for this signature in database
GPG Key ID: B5669F9493CDE38D
4 changed files with 7 additions and 6 deletions

View File

@ -65,7 +65,7 @@ class BudgetController extends Controller
public function budgets(AutocompleteRequest $request): JsonResponse
{
$data = $request->getData();
$result = $this->repository->searchBudget($data['query']);
$result = $this->repository->searchBudget($data['query'], $data['limit']);
$filtered = $result->map(
static function (Budget $item) {
return [

View File

@ -238,10 +238,11 @@ class BudgetRepository implements BudgetRepositoryInterface
/**
* @param string $query
* @param int $limit
*
* @return Collection
*/
public function searchBudget(string $query): Collection
public function searchBudget(string $query, int $limit): Collection
{
$search = $this->user->budgets();
@ -251,7 +252,7 @@ class BudgetRepository implements BudgetRepositoryInterface
$search->orderBy('order', 'ASC')
->orderBy('name', 'ASC')->where('active', 1);
return $search->get();
return $search->take($limit)->get();
}
/**

View File

@ -138,10 +138,10 @@ interface BudgetRepositoryInterface
/**
* @param string $query
*
* @param int $limit
* @return Collection
*/
public function searchBudget(string $query): Collection;
public function searchBudget(string $query, int $limit): Collection;
/**
* @param Budget $budget

View File

@ -248,7 +248,7 @@ class Search implements SearchInterface
break;
break;
case 'budget':
$result = $this->budgetRepository->searchBudget($modifier['value']);
$result = $this->budgetRepository->searchBudget($modifier['value'], 25);
if ($result->count() > 0) {
$collector->setBudgets($result);
}