Skip to content

Instantly share code, notes, and snippets.

@MillerAdulu
Last active April 15, 2020 19:03
Show Gist options
  • Save MillerAdulu/5d3da961639e62fe05ad7c800c3cd383 to your computer and use it in GitHub Desktop.
Save MillerAdulu/5d3da961639e62fe05ad7c800c3cd383 to your computer and use it in GitHub Desktop.
Seed data with foreign keys
<?php
use Faker\Generator as Faker;
use App\Member;
$factory->define(App\MemberDeposit::class, function (Faker $faker) {
$members = Member::all()->pluck('member_id')->toArray();
return [
'member_id' => $faker->randomElement($members),
'payment_method_id' => $faker->randomElement($payment_methods),
'deposit_amount' => $faker->randomFloat(2, 0, 999999),
'comment' => $faker->word
];
});
<?php
use App\MaritalStatus;
use Faker\Generator as Faker;
$factory->define(App\Member::class, function (Faker $faker) {
$marital_statuses = MaritalStatus::all()->pluck('marital_status_id')->toArray();
return [
'identification_number' => $faker->ean13,
'first_name' => $faker->firstName,
'last_name' => $faker->lastName,
'other_name' => $faker->word,
'date_of_birth' => $faker->date('Y-m-d', 'now'),
'phone_number' => $faker->e164PhoneNumber,
'email' => $faker->email,
'kra_pin' => $faker->swiftBicNumber,
'gender' => $faker->boolean,
'passport_photo' => $faker->imageUrl($width = 200, $height = 200),
'marital_status_id' => $faker->randomElement($marital_statuses),
'proposed_monthly_deposit' => $faker->randomFloat(2, 0, 999999),
];
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment