🗃️ Ajoute les tags

Pour #1
This commit is contained in:
cdesmidt 2019-09-30 16:31:16 +02:00
parent 333f6feafb
commit a7715c8460
5 changed files with 96 additions and 1 deletions

12
app/PostsTag.php Normal file
View File

@ -0,0 +1,12 @@
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class PostsTag extends Model
{
protected $fillable = [
'post_id', 'tag_id',
];
}

10
app/Tag.php Normal file
View File

@ -0,0 +1,10 @@
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Tag extends Model
{
//
}

View File

@ -0,0 +1,42 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateTags extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('tags', function (Blueprint $table) {
$table->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');
}
}

View File

@ -11,6 +11,8 @@ class DatabaseSeeder extends Seeder
*/
public function run()
{
// $this->call(UsersTableSeeder::class);
$this->call([
TagsTableSeeder::class
]);
}
}

View File

@ -0,0 +1,29 @@
<?php
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
class TagsTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
DB::table('tags')->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()]);
}
}