1 | <?php
|
---|
2 |
|
---|
3 | use Illuminate\Support\Str;
|
---|
4 | use Faker\Generator as Faker;
|
---|
5 |
|
---|
6 | /*
|
---|
7 | |--------------------------------------------------------------------------
|
---|
8 | | Model Factories
|
---|
9 | |--------------------------------------------------------------------------
|
---|
10 | |
|
---|
11 | | This directory should contain each of the model factory definitions for
|
---|
12 | | your application. Factories provide a convenient way to generate new
|
---|
13 | | model instances for testing / seeding your application's database.
|
---|
14 | |
|
---|
15 | */
|
---|
16 |
|
---|
17 | $factory->define(App\Models\User::class, function (Faker $faker) {
|
---|
18 |
|
---|
19 | $name = $faker->firstName($gender = 'male'|'female');
|
---|
20 | $surname = $faker->lastName;
|
---|
21 |
|
---|
22 | $countryCodes = array();
|
---|
23 |
|
---|
24 | foreach(country()->all() as $cCode => $cName) {
|
---|
25 | array_push($countryCodes, $cCode);
|
---|
26 | }
|
---|
27 |
|
---|
28 | return [
|
---|
29 | 'name' => $name,
|
---|
30 | 'surname' => $surname,
|
---|
31 | 'username' => $faker->userName,
|
---|
32 | 'password' => '$2y$10$TKh8H1.PfQx37YgCzwiKb.KjNyWgaHb9cbcoQgdIVFlYg7B77UdFm', // secret,
|
---|
33 | 'email' => $faker->unique()->safeEmail,
|
---|
34 | 'country_code' => $faker->randomElement($array = $countryCodes),
|
---|
35 | 'mobile_number' => $faker->phoneNumber,
|
---|
36 | 'role_id' => $faker->randomElement($array = array(1, 2, 3, 4)),
|
---|
37 | 'is_active' => $faker->boolean,
|
---|
38 | 'is_confirmed' => $faker->boolean
|
---|
39 | ];
|
---|
40 | });
|
---|
41 |
|
---|
42 | $factory->afterCreating(\App\Models\User::class, function ($user, $faker) {
|
---|
43 | $user->userProfile()->create([
|
---|
44 | "user_id" => $user->id,
|
---|
45 | "profile_link" => $user->generateProfileLink($user->name, $user->surname),
|
---|
46 | "technoblog_email" => $user->generateTechnoblogEmail($user->name, $user->surname),
|
---|
47 | "facebook_link" => $user->generateProfileLink($user->name, $user->surname),
|
---|
48 | "instagram_link" => $user->generateProfileLink($user->name, $user->surname),
|
---|
49 | "twitter_link" => $user->generateProfileLink($user->name, $user->surname),
|
---|
50 | "youtube_link" => $user->generateProfileLink($user->name, $user->surname),
|
---|
51 | "skype_link" => $user->generateProfileLink($user->name, $user->surname),
|
---|
52 | "created_at" => \Carbon\Carbon::now()
|
---|
53 | ]);
|
---|
54 | });
|
---|