mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-15 08:35:00 +00:00
Replace Laravel binder with own binder. This will save in queries and increase security.
This commit is contained in:
@@ -47,25 +47,27 @@ class BudgetLimit extends Model
|
||||
protected $dates = ['start_date', 'end_date'];
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param string $value
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function routeBinder($value)
|
||||
public static function routeBinder(string $value): BudgetLimit
|
||||
{
|
||||
if (auth()->check()) {
|
||||
$object = self::where('budget_limits.id', $value)
|
||||
->leftJoin('budgets', 'budgets.id', '=', 'budget_limits.budget_id')
|
||||
->where('budgets.user_id', auth()->user()->id)
|
||||
->first(['budget_limits.*']);
|
||||
if ($object) {
|
||||
return $object;
|
||||
$budgetLimitId = intval($value);
|
||||
$budgetLimit = self::where('budget_limits.id', $budgetLimitId)
|
||||
->leftJoin('budgets', 'budgets.id', '=', 'budget_limits.budget_id')
|
||||
->where('budgets.user_id', auth()->user()->id)
|
||||
->first(['budget_limits.*']);
|
||||
if (!is_null($budgetLimit)) {
|
||||
return $budgetLimit;
|
||||
}
|
||||
}
|
||||
throw new NotFoundHttpException;
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function budget()
|
||||
@@ -74,6 +76,7 @@ class BudgetLimit extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @param $value
|
||||
*/
|
||||
public function setAmountAttribute($value)
|
||||
|
Reference in New Issue
Block a user