diff --git a/database/factories/Transaction.php b/database/factories/Transaction.php index 91335775e..f5463f19f 100644 --- a/database/factories/Transaction.php +++ b/database/factories/Transaction.php @@ -27,6 +27,8 @@ class Transaction extends Factory $types = array_merge($this->getIncomeTypes(), $this->getExpenseTypes()); $type = $this->faker->randomElement($types); + $category_type = in_array($type, $this->getIncomeTypes()) ? 'income' : 'expense'; + return [ 'company_id' => $this->company->id, 'type' => $type, @@ -36,7 +38,7 @@ class Transaction extends Factory 'currency_code' => setting('default.currency'), 'currency_rate' => '1.0', 'description' => $this->faker->text(5), - 'category_id' => $this->company->categories()->type($type)->get()->random(1)->pluck('id')->first(), + 'category_id' => $this->company->categories()->$category_type()->get()->random(1)->pluck('id')->first(), 'reference' => $this->faker->text(5), 'payment_method' => setting('default.payment_method'), ];