leftjoin('budget_limits', 'budget_limits.id', '=', 'limit_repetitions.budget_limit_id') ->leftJoin('budgets', 'budgets.id', '=', 'budget_limits.budget_id') ->where('budgets.user_id', Auth::user()->id) ->first(['limit_repetitions.*']); if ($object) { return $object; } } throw new NotFoundHttpException; } /** * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function budgetLimit() { return $this->belongsTo('FireflyIII\Models\BudgetLimit'); } /** * * @param Builder $query * @param Carbon $date * */ public function scopeAfter(Builder $query, Carbon $date) { $query->where('limit_repetitions.startdate', '>=', $date->format('Y-m-d 00:00:00')); } /** * * @param Builder $query * @param Carbon $date * */ public function scopeBefore(Builder $query, Carbon $date) { $query->where('limit_repetitions.enddate', '<=', $date->format('Y-m-d 00:00:00')); } /** * @param $value */ public function setAmountAttribute($value) { $this->attributes['amount'] = strval(round($value, 2)); } }