. */ declare(strict_types=1); namespace FireflyIII\Models; use Illuminate\Database\Eloquent\Model; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** * Class BudgetLimit. */ class BudgetLimit extends Model { /** * The attributes that should be casted to native types. * * @var array */ protected $casts = [ 'created_at' => 'datetime', 'updated_at' => 'datetime', 'start_date' => 'date', 'end_date' => 'date', 'repeats' => 'boolean', ]; /** * @param string $value * * @return mixed */ public static function routeBinder(string $value): BudgetLimit { if (auth()->check()) { $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() { return $this->belongsTo('FireflyIII\Models\Budget'); } /** * @codeCoverageIgnore * * @param $value */ public function setAmountAttribute($value) { $this->attributes['amount'] = strval(round($value, 12)); } }