. */ declare(strict_types=1); namespace FireflyIII\Support\Binder; use FireflyIII\Models\Budget; use Illuminate\Routing\Route; use Illuminate\Support\Collection; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** * Class BudgetList. */ class BudgetList implements BinderInterface { /** * @param string $value * @param Route $route * * @return Collection * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException */ public static function routeBinder(string $value, Route $route): Collection { if (auth()->check()) { $list = []; $incoming = explode(',', $value); foreach ($incoming as $entry) { $list[] = intval($entry); } $list = array_unique($list); if (count($list) === 0) { throw new NotFoundHttpException; // @codeCoverageIgnore } /** @var \Illuminate\Support\Collection $collection */ $collection = auth()->user()->budgets() ->where('active', 1) ->whereIn('id', $list) ->get(); // add empty budget if applicable. if (in_array(0, $list)) { $collection->push(new Budget); } if ($collection->count() > 0) { return $collection; } } throw new NotFoundHttpException; } }