ModelFactory.php
1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
use Faker\Generator;
use App\Access\Model\Role\Role;
use App\Access\Model\User\User;
/*
|--------------------------------------------------------------------------
| Model Factories
|--------------------------------------------------------------------------
|
| Here you may define all of your model factories. Model factories give
| you a convenient way to create models for testing and seeding your
| database. Just tell the factory how a default model should look.
|
*/
$factory->define(User::class, function (Generator $faker) {
static $password;
return [
'first_name' => $faker->firstName,
'last_name' => $faker->lastName,
'email' => $faker->safeEmail,
'password' => $password ?: $password = bcrypt('secret'),
'remember_token' => str_random(10),
'confirmation_code' => md5(uniqid(mt_rand(), true)),
];
});
$factory->state(User::class, 'active', function () {
return [
'status' => 1,
];
});
$factory->state(User::class, 'inactive', function () {
return [
'status' => 0,
];
});
$factory->state(User::class, 'confirmed', function () {
return [
'confirmed' => 1,
];
});
$factory->state(User::class, 'unconfirmed', function () {
return [
'confirmed' => 0,
];
});
/*
* Roles
*/
$factory->define(Role::class, function (Generator $faker) {
return [
'name' => $faker->name,
'all' => 0,
'sort' => $faker->numberBetween(1, 100),
];
});
$factory->state(Role::class, 'admin', function () {
return [
'all' => 1,
];
});