mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Fixed budget list binder.
This commit is contained in:
parent
1f263f60a7
commit
ef4e964c94
52
app/Support/Binder/BudgetList.php
Normal file
52
app/Support/Binder/BudgetList.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/**
|
||||
* BudgetList.php
|
||||
* Copyright (C) 2016 Sander Dorigo
|
||||
*
|
||||
* This software may be modified and distributed under the terms
|
||||
* of the MIT license. See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace FireflyIII\Support\Binder;
|
||||
|
||||
use Auth;
|
||||
use FireflyIII\Models\Budget;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
|
||||
/**
|
||||
* Class BudgetList
|
||||
*
|
||||
* @package FireflyIII\Support\Binder
|
||||
*/
|
||||
class BudgetList implements BinderInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param $route
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function routeBinder($value, $route)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
if ($object->count() > 0) {
|
||||
return $object;
|
||||
}
|
||||
}
|
||||
throw new NotFoundHttpException;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user