commit 92577cfd39fa96891b10c7168bf56f195806bf81
Author: Marek Lovčí <mareklovci@gmail.com>
Date:   Sun Apr 26 15:48:01 2020 +0200

    Seeding

diff --git a/app/Artefact.php b/app/Artefact.php
index f946b93..6b2763f 100644
--- a/app/Artefact.php
+++ b/app/Artefact.php
@@ -7,18 +7,9 @@ use Illuminate\Database\Eloquent\Model;
 class Artefact extends Model
 {
     // Table Name
-    protected $table = 'artefacts';//unnecessery?
+    protected $table = 'artefacts';
     // Primary Key
-    public $primaryKey = 'id';//unnecessery?
-
-    /**
-     * The model's default values for attributes.
-     *
-     * @var array
-     */
-    /*protected $attributes = [
-        'likes' => 0,
-    ];*/
+    public $primaryKey = 'id';
 
     /**
      * Indicates if the model should be timestamped.
@@ -50,7 +41,4 @@ class Artefact extends Model
     {
         return $this->belongsToMany('App\User');
     }
-
-
-
 }
diff --git a/app/Category.php b/app/Category.php
index cb2d9c0..7912dbf 100644
--- a/app/Category.php
+++ b/app/Category.php
@@ -9,8 +9,7 @@ class Category extends Model
     // Table Name
     protected $table = 'categories';
     // Primary Key
-    public $primaryKey = 'id';//unnecessery?
-
+    public $primaryKey = 'id';
 
     /**
      * Indicates if the model should be timestamped.
@@ -20,12 +19,10 @@ class Category extends Model
     public $timestamps = false;
 
     /**
-     * Get the artefacts for the catagory.
+     * Get the artefacts for the category.
      */
     public function artefacts()
     {
         return $this->belongsToMany('App\Artefact');
     }
-
-
 }
diff --git a/app/Metadata.php b/app/Metadata.php
index 77e787b..120ce6b 100644
--- a/app/Metadata.php
+++ b/app/Metadata.php
@@ -7,18 +7,9 @@ use Illuminate\Database\Eloquent\Model;
 class Metadata extends Model
 {
     // Table Name
-    protected $table = 'metadata';//same name could make problems
+    protected $table = 'metadata';
     // Primary Key
-    public $primaryKey = 'id';//unnecessery?
-
-    /**
-     * The model's default values for attributes.
-     *
-     * @var array
-     */
-    /*protected $attributes = [
-        'likes' => 0,
-    ];*/
+    public $primaryKey = 'id';
 
     /**
      * Indicates if the model should be timestamped.
diff --git a/app/User.php b/app/User.php
index 04182d3..da5cf4a 100644
--- a/app/User.php
+++ b/app/User.php
@@ -2,7 +2,6 @@
 
 namespace App;
 
-use Illuminate\Contracts\Auth\MustVerifyEmail;
 use Illuminate\Foundation\Auth\User as Authenticatable;
 use Illuminate\Notifications\Notifiable;
 
@@ -13,7 +12,7 @@ class User extends Authenticatable
     // Table Name
     protected $table = 'users';
     // Primary Key
-    public $primaryKey = 'id';//unnecessery?
+    public $primaryKey = 'id';
 
     /**
      * The attributes that are mass assignable.
diff --git a/database/factories/ArtefactFactory.php b/database/factories/ArtefactFactory.php
new file mode 100644
index 0000000..f074539
--- /dev/null
+++ b/database/factories/ArtefactFactory.php
@@ -0,0 +1,21 @@
+<?php
+
+/** @var Factory $factory */
+/** @var Faker $faker */
+
+use App\Artefact;
+use App\Category;
+use Faker\Generator as Faker;
+use Illuminate\Database\Eloquent\Factory;
+
+$factory->define(Artefact::class, function ($faker) {
+    return [
+        'name' => $faker->opera,
+        'author' => $faker->name,
+        'made_in' => $faker->countryCode,
+        'publisher' => $faker->company,
+        'year' => rand(1800, 2020),
+        'pages' => rand(0, 2000),
+        'main_category_id' => factory(Category::class)->create()->id,
+    ];
+});
diff --git a/database/factories/CategoryFactory.php b/database/factories/CategoryFactory.php
new file mode 100644
index 0000000..3879434
--- /dev/null
+++ b/database/factories/CategoryFactory.php
@@ -0,0 +1,14 @@
+<?php
+
+/** @var Factory $factory */
+
+use App\Category;
+use Faker\Generator as Faker;
+use Illuminate\Database\Eloquent\Factory;
+
+$factory->define(Category::class, function (Faker $faker) {
+    return [
+        'nameCZ' => $faker->colorName,
+        'nameEN' => $faker->hexColor,
+    ];
+});
diff --git a/database/factories/MetadataFactory.php b/database/factories/MetadataFactory.php
new file mode 100644
index 0000000..58693a5
--- /dev/null
+++ b/database/factories/MetadataFactory.php
@@ -0,0 +1,19 @@
+<?php
+
+/** @var Factory $factory */
+/** @var Faker $faker */
+
+use App\Artefact;
+use App\Metadata;
+use Faker\Generator as Faker;
+use Illuminate\Database\Eloquent\Factory;
+
+$factory->define(Metadata::class, function ($faker) use ($factory) {
+    return [
+        'name' => $faker->streetName,
+        'noteCZ' => $faker->paragraph,
+        'noteEN' => $faker->paragraph,
+        'page' => rand(0, 2000),
+        'artefact_id' => factory(Artefact::class)->create()->id
+    ];
+});
diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php
index 741edea..e9cbede 100644
--- a/database/factories/UserFactory.php
+++ b/database/factories/UserFactory.php
@@ -1,9 +1,10 @@
 <?php
 
-/** @var \Illuminate\Database\Eloquent\Factory $factory */
+/** @var Factory $factory */
 
 use App\User;
 use Faker\Generator as Faker;
+use Illuminate\Database\Eloquent\Factory;
 use Illuminate\Support\Str;
 
 /*
@@ -22,7 +23,9 @@ $factory->define(User::class, function (Faker $faker) {
         'name' => $faker->name,
         'email' => $faker->unique()->safeEmail,
         'email_verified_at' => now(),
-        'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
+        'password' => bcrypt($faker->unique()->password),
         'remember_token' => Str::random(10),
+        'created_at' => now(),
+        'updated_at' => now(),
     ];
 });
diff --git a/database/seeds/DatabaseSeeder.php b/database/seeds/DatabaseSeeder.php
index 91cb6d1..d971dd6 100644
--- a/database/seeds/DatabaseSeeder.php
+++ b/database/seeds/DatabaseSeeder.php
@@ -1,6 +1,8 @@
 <?php
 
 use Illuminate\Database\Seeder;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Str;
 
 class DatabaseSeeder extends Seeder
 {
@@ -11,6 +13,55 @@ class DatabaseSeeder extends Seeder
      */
     public function run()
     {
-        // $this->call(UsersTableSeeder::class);
+        DB::table('users')->insert([
+            'name' => 'admin',
+            'email' => 'admin@kaplicky.com',
+            'email_verified_at' => now(),
+            'password' => bcrypt('admin'),
+            'remember_token' => Str::random(10),
+            'created_at' => now(),
+            'updated_at' => now(),
+        ]);
+
+        // Populate users
+        factory(App\User::class, 19)->create();
+
+        // Populate categories
+        factory(App\Category::class, 80)->create();
+
+        // Populate artefacts with metadata
+        factory(App\Artefact::class, 300)->create()->each(function ($u) {
+            $u->metadata()->saveMany(factory(App\Metadata::class, 10)->make());
+        });
+
+        // Get all the categories attaching up to 1 random categories to each user
+        $categories = App\Category::all();
+
+        // Populate the artefact_category pivot table
+        App\Artefact::all()->each(function ($artefact) use ($categories) {
+            $artefact->categories()->attach(
+                $categories->random(1)->pluck('id')->toArray()
+            );
+        });
+
+        // Get all the metadata attaching up to 50 random metadata to each user
+        $artefacts = App\Metadata::all();
+
+        // Populate the artefact_user pivot table
+        App\User::all()->each(function ($user) use ($artefacts) {
+            $user->likesArtefacts()->attach(
+                $artefacts->random(rand(1, 50))->pluck('id')->toArray()
+            );
+        });
+
+        // Get all the metadata attaching up to 50 random metadata to each user
+        $metadata = App\Metadata::all();
+
+        // Populate the metadata_user pivot table
+        App\User::all()->each(function ($user) use ($metadata) {
+            $user->likesMetadata()->attach(
+                $metadata->random(rand(1, 50))->pluck('id')->toArray()
+            );
+        });
     }
 }
