Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 92577cfd

Přidáno uživatelem Marek Lovčí před více než 4 roky(ů)

Seeding

Zobrazit rozdíly:

database/seeds/DatabaseSeeder.php
1 1
<?php
2 2

  
3 3
use Illuminate\Database\Seeder;
4
use Illuminate\Support\Facades\DB;
5
use Illuminate\Support\Str;
4 6

  
5 7
class DatabaseSeeder extends Seeder
6 8
{
......
11 13
     */
12 14
    public function run()
13 15
    {
14
        // $this->call(UsersTableSeeder::class);
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
        ]);
25

  
26
        // Populate users
27
        factory(App\User::class, 19)->create();
28

  
29
        // Populate categories
30
        factory(App\Category::class, 80)->create();
31

  
32
        // Populate artefacts with metadata
33
        factory(App\Artefact::class, 300)->create()->each(function ($u) {
34
            $u->metadata()->saveMany(factory(App\Metadata::class, 10)->make());
35
        });
36

  
37
        // Get all the categories attaching up to 1 random categories to each user
38
        $categories = App\Category::all();
39

  
40
        // Populate the artefact_category pivot table
41
        App\Artefact::all()->each(function ($artefact) use ($categories) {
42
            $artefact->categories()->attach(
43
                $categories->random(1)->pluck('id')->toArray()
44
            );
45
        });
46

  
47
        // Get all the metadata attaching up to 50 random metadata to each user
48
        $artefacts = App\Metadata::all();
49

  
50
        // Populate the artefact_user pivot table
51
        App\User::all()->each(function ($user) use ($artefacts) {
52
            $user->likesArtefacts()->attach(
53
                $artefacts->random(rand(1, 50))->pluck('id')->toArray()
54
            );
55
        });
56

  
57
        // Get all the metadata attaching up to 50 random metadata to each user
58
        $metadata = App\Metadata::all();
59

  
60
        // Populate the metadata_user pivot table
61
        App\User::all()->each(function ($user) use ($metadata) {
62
            $user->likesMetadata()->attach(
63
                $metadata->random(rand(1, 50))->pluck('id')->toArray()
64
            );
65
        });
15 66
    }
16 67
}

Také k dispozici: Unified diff