parent
333f6feafb
commit
a7715c8460
12
app/PostsTag.php
Normal file
12
app/PostsTag.php
Normal 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
10
app/Tag.php
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class Tag extends Model
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
42
database/migrations/2019_09_26_092440_create_tags.php
Normal file
42
database/migrations/2019_09_26_092440_create_tags.php
Normal 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');
|
||||||
|
}
|
||||||
|
}
|
@ -11,6 +11,8 @@ class DatabaseSeeder extends Seeder
|
|||||||
*/
|
*/
|
||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
// $this->call(UsersTableSeeder::class);
|
$this->call([
|
||||||
|
TagsTableSeeder::class
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
29
database/seeds/TagsTableSeeder.php
Normal file
29
database/seeds/TagsTableSeeder.php
Normal 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()]);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user