From a7715c8460bfb55021a13a29110d5253c869f0a5 Mon Sep 17 00:00:00 2001 From: cdesmidt Date: Mon, 30 Sep 2019 16:31:16 +0200 Subject: [PATCH] :card_file_box: Ajoute les tags Pour #1 --- app/PostsTag.php | 12 ++++++ app/Tag.php | 10 +++++ .../2019_09_26_092440_create_tags.php | 42 +++++++++++++++++++ database/seeds/DatabaseSeeder.php | 4 +- database/seeds/TagsTableSeeder.php | 29 +++++++++++++ 5 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 app/PostsTag.php create mode 100644 app/Tag.php create mode 100644 database/migrations/2019_09_26_092440_create_tags.php create mode 100644 database/seeds/TagsTableSeeder.php diff --git a/app/PostsTag.php b/app/PostsTag.php new file mode 100644 index 0000000..7fb54c9 --- /dev/null +++ b/app/PostsTag.php @@ -0,0 +1,12 @@ +bigIncrements('id'); + $table->timestamps(); + $table->string('name')->unique(); + }); + + Schema::create('posts_tags', function (Blueprint $table) { + $table->bigIncrements('id'); + $table->timestamps(); + $table->bigInteger('post_id'); + $table->bigInteger('tag_id'); + $table->foreign('post_id')->references('id')->on('posts'); + $table->foreign('tag_id')->references('id')->on('tags'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('tags'); + Schema::dropIfExists('posts_tags'); + } +} diff --git a/database/seeds/DatabaseSeeder.php b/database/seeds/DatabaseSeeder.php index 91cb6d1..23fe5d1 100755 --- a/database/seeds/DatabaseSeeder.php +++ b/database/seeds/DatabaseSeeder.php @@ -11,6 +11,8 @@ class DatabaseSeeder extends Seeder */ public function run() { - // $this->call(UsersTableSeeder::class); + $this->call([ + TagsTableSeeder::class + ]); } } diff --git a/database/seeds/TagsTableSeeder.php b/database/seeds/TagsTableSeeder.php new file mode 100644 index 0000000..05fa9a8 --- /dev/null +++ b/database/seeds/TagsTableSeeder.php @@ -0,0 +1,29 @@ +insert(['name' => 'Voyages', 'created_at' => \Carbon\Carbon::now()]); + DB::table('tags')->insert(['name' => 'Étapes', 'created_at' => \Carbon\Carbon::now()]); + DB::table('tags')->insert(['name' => 'Santé', 'created_at' => \Carbon\Carbon::now()]); + DB::table('tags')->insert(['name' => 'Humeur', 'created_at' => \Carbon\Carbon::now()]); + DB::table('tags')->insert(['name' => 'Idée', 'created_at' => \Carbon\Carbon::now()]); + DB::table('tags')->insert(['name' => 'Connaissance', 'created_at' => \Carbon\Carbon::now()]); + DB::table('tags')->insert(['name' => 'Habitudes', 'created_at' => \Carbon\Carbon::now()]); + DB::table('tags')->insert(['name' => 'Nourriture', 'created_at' => \Carbon\Carbon::now()]); + DB::table('tags')->insert(['name' => 'Gratitude', 'created_at' => \Carbon\Carbon::now()]); + DB::table('tags')->insert(['name' => 'Fitness', 'created_at' => \Carbon\Carbon::now()]); + DB::table('tags')->insert(['name' => 'Rêves', 'created_at' => \Carbon\Carbon::now()]); + DB::table('tags')->insert(['name' => 'Travail', 'created_at' => \Carbon\Carbon::now()]); + } +}