Metadata - Tags の多対多リレーション追加

This commit is contained in:
shibafu 2019-04-29 11:40:03 +09:00
parent 91c786199a
commit 1322e89b86
2 changed files with 38 additions and 0 deletions

View File

@ -14,4 +14,9 @@ class Metadata extends Model
protected $visible = ['url', 'title', 'description', 'image', 'expires_at'];
protected $dates = ['created_at', 'updated_at', 'expires_at'];
public function tags()
{
return $this->belongsToMany(Tag::class)->withTimestamps();
}
}

View File

@ -0,0 +1,33 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateMetadataTagTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('metadata_tag', function (Blueprint $table) {
$table->increments('id');
$table->text('metadata_url')->index();
$table->integer('tag_id')->index();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('metadata_tag');
}
}