Closed MACscr closed 3 years ago
The way I normally do it is I would seed contacts BEFORE transactions, then in my transaction seeder do something like this:
public function definition(Generator $faker)
{
return [
'contact_id' => Contact::inRandomOrder()->first()->id,
'description' => $faker->words,
'payment_gateway' => 'square',
'gateway_transaction_id' => $faker->unique()->numerify('########'),
'amount' => $faker->randomFloat(2, 10, 20),
'fees' => $faker->randomFloat(2, 0, 0.4),
];
}
Perfect! Thanks!
One thing i am struggling to figure out how to do relations with the seed data in the definition(). Not sure how i can make that 'contact_id' in the seed related to an actual contact from the Contact model. Will be useful to know for other uses. Right now i just have a hard contact id set of 1.