1
|
<?php
|
2
|
|
3
|
use Illuminate\Database\Seeder;
|
4
|
use Illuminate\Support\Facades\DB;
|
5
|
use Illuminate\Support\Str;
|
6
|
|
7
|
class DatabaseSeeder extends Seeder
|
8
|
{
|
9
|
/**
|
10
|
* Seed the application's database.
|
11
|
*
|
12
|
* @return void
|
13
|
*/
|
14
|
public function run()
|
15
|
{
|
16
|
DB::table('users')->insert([
|
17
|
'name' => 'admin',
|
18
|
'email' => 'admin@kaplicky.com',
|
19
|
'email_verified_at' => now(),
|
20
|
'password' => bcrypt('admin'),
|
21
|
'remember_token' => Str::random(10),
|
22
|
'created_at' => now(),
|
23
|
'updated_at' => now(),
|
24
|
'register_hash' => Str::random(10),
|
25
|
]);
|
26
|
|
27
|
// Populate users
|
28
|
factory(App\User::class, 19)->create();
|
29
|
|
30
|
// Populate categories
|
31
|
factory(App\Category::class, 80)->create();
|
32
|
|
33
|
// Populate artefacts with metadata
|
34
|
factory(App\Artefact::class, 300)->create()->each(function ($u) {
|
35
|
$u->metadata()->saveMany(factory(App\Metadata::class, 10)->make());
|
36
|
});
|
37
|
|
38
|
// Get all the categories attaching up to 1 random categories to each user
|
39
|
$categories = App\Category::all();
|
40
|
|
41
|
// Populate the artefact_category pivot table
|
42
|
App\Artefact::all()->each(function ($artefact) use ($categories) {
|
43
|
$artefact->categories()->attach(
|
44
|
$categories->random(1)->pluck('id')->toArray()
|
45
|
);
|
46
|
});
|
47
|
|
48
|
// Get all the metadata attaching up to 50 random metadata to each user
|
49
|
$artefacts = App\Metadata::all();
|
50
|
|
51
|
// Populate the artefact_user pivot table
|
52
|
App\User::all()->each(function ($user) use ($artefacts) {
|
53
|
$user->likesArtefacts()->attach(
|
54
|
$artefacts->random(rand(1, 50))->pluck('id')->toArray()
|
55
|
);
|
56
|
});
|
57
|
|
58
|
// Get all the metadata attaching up to 50 random metadata to each user
|
59
|
$metadata = App\Metadata::all();
|
60
|
|
61
|
// Populate the metadata_user pivot table
|
62
|
App\User::all()->each(function ($user) use ($metadata) {
|
63
|
$user->likesMetadata()->attach(
|
64
|
$metadata->random(rand(1, 50))->pluck('id')->toArray()
|
65
|
);
|
66
|
});
|
67
|
}
|
68
|
}
|