One to Many & One to One Polymorphic Relationships - Laravel Eloquent Relationships (phần 2)
Ví dụ 1: Tao database taggables
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateTaggablesTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up() {
Schema::create('taggables', function (Blueprint $table) {
$table->bigInteger('tag_id');
$table->bigInteger('taggable_id');
$table->string('taggable_type');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down() {
Schema::dropIfExists('taggables');
}
}Ví dụ 2: Tao database videos

Ví dụ 3: Bỏ taggable_type đầy đủ sang dạng khuyết :)




PreviousOne to Many & One to One Polymorphic Relationships - Laravel Eloquent Relationships (phần 1)NextEloquent: relationships in laravel-Phần 1
Last updated