Expand binder test.

This commit is contained in:
James Cole
2017-12-25 15:30:50 +01:00
parent 58eaf3bccc
commit 01818af963
6 changed files with 411 additions and 40 deletions

View File

@@ -41,20 +41,29 @@ class BudgetList implements BinderInterface
public static function routeBinder(string $value, Route $route): Collection
{
if (auth()->check()) {
$ids = explode(',', $value);
/** @var \Illuminate\Support\Collection $object */
$object = Budget::where('active', 1)
->whereIn('id', $ids)
->where('user_id', auth()->user()->id)
->get();
// add empty budget if applicable.
if (in_array('0', $ids)) {
$object->push(new Budget);
$list = [];
$incoming = explode(',', $value);
foreach ($incoming as $entry) {
$list[] = intval($entry);
}
$list = array_unique($list);
if (count($list) === 0) {
throw new NotFoundHttpException; // @codeCoverageIgnore
}
if ($object->count() > 0) {
return $object;
/** @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;