budgets()->first(); if (!is_null($budget)) { $name = strtolower($budget->name); // match on journal: if ($name === strtolower($this->triggerValue)) { Log::debug(sprintf('RuleTrigger BudgetIs for journal #%d: "%s" is "%s", return true.', $journal->id, $name, $this->triggerValue)); return true; } } if (is_null($budget)) { // perhaps transactions have this budget? /** @var Transaction $transaction */ foreach ($journal->transactions as $transaction) { $budget = $transaction->budgets()->first(); if (!is_null($budget)) { $name = strtolower($budget->name); if ($name === strtolower($this->triggerValue)) { Log::debug( sprintf( 'RuleTrigger BudgetIs for journal #%d (transaction #%d): "%s" is "%s", return true.', $journal->id, $transaction->id, $name, $this->triggerValue ) ); return true; } } } } Log::debug(sprintf('RuleTrigger BudgetIs for journal #%d: does not have budget "%s", return false.', $journal->id, $this->triggerValue)); return false; } }