Files
timebank-cc-public/database/factories/TransactionFactory.php
T

41 lines
1.1 KiB
PHP

<?php
namespace Database\Factories;
use App\Models\Account;
use App\Models\Transaction;
use App\Models\TransactionType;
use Illuminate\Database\Eloquent\Factories\Factory;
class TransactionFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Transaction::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
//TODO: use all fields
$fromAccountId = Account::all()->random()->id;
$toAccountId = Account::all()->random()->id;
return [
'from_account_id' => $fromAccountId,
'to_account_id' => $toAccountId,
// 'creator_user_id' => Account::find($fromAccountId)->accountable->id,
'creator_user_id' => 1,
'amount' => $this->faker->numberBetween(15, 2000),
'description' => $this->faker->sentence(),
// Transactions must have an existing type (see Transaction::booted())
'transaction_type_id' => fn () => TransactionType::orderBy('id')->value('id'),
];
}
}