action = $action; } /** * @param TransactionJournal $journal * * @return bool */ public function act(TransactionJournal $journal): bool { /** @var BudgetRepositoryInterface $repository */ $repository = app(BudgetRepositoryInterface::class, [$journal->user]); $search = $this->action->action_value; $budgets = $repository->getActiveBudgets(); $budget = $budgets->filter( function (Budget $current) use ($search) { return $current->name == $search; } )->first(); if (is_null($budget)) { Log::debug(sprintf('RuleAction SetBudget could not set budget of journal #%d to "%s" because no such budget exists.', $journal->id, $search)); return true; } if ($journal->transactionType->type == TransactionType::TRANSFER) { Log::debug(sprintf('RuleAction SetBudget could not set budget of journal #%d to "%s" because journal is a transfer.', $journal->id, $search)); return true; } Log::debug(sprintf('RuleAction SetBudget set the budget of journal #%d to budget #%d ("%s").', $journal->id, $budget->id, $budget->name)); $journal->budgets()->sync([$budget->id]); return true; } }