Replace Laravel binder with own binder. This will save in queries and increase security.

This commit is contained in:
James Cole
2017-12-25 08:45:23 +01:00
parent 96ccce5db3
commit bf390b65d9
37 changed files with 1671 additions and 142 deletions

View File

@@ -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)