. */ declare(strict_types=1); namespace FireflyIII\Models; use Illuminate\Database\Eloquent\Model; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** * Class BudgetLimit * * @package FireflyIII\Models */ 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', ]; /** @var array */ protected $dates = ['start_date', 'end_date']; /** * @param $value * * @return mixed */ public static function routeBinder($value) { 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; } } throw new NotFoundHttpException; } /** * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function budget() { return $this->belongsTo('FireflyIII\Models\Budget'); } /** * @return \Illuminate\Database\Eloquent\Relations\HasMany */ public function limitrepetitions() { return $this->hasMany('FireflyIII\Models\LimitRepetition'); } /** * @param $value */ public function setAmountAttribute($value) { $this->attributes['amount'] = strval(round($value, 12)); } }