Полиморфные отношения

Один к одному (полиморфное)

Миграции для моделей
posts
    id - integer
    name - string

users
    id - integer
    name - string

images
    id - integer
    url - string
    imageable_id - integer
    imageable_type - string
create_users_table
public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->timestamps();
        });
    }
create_images_table
public function up()
    {
        Schema::create('images', function (Blueprint $table) {
            $table->id();
            $table->string('url');
            $table->integer('imageable_id')->nullable();
            $table->string('imageable_type')->nullable();
            $table->timestamps();
        });
    }
create_posts_table
public function up()
    {
        Schema::create('posts', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->timestamps();
        });
    }

Создание отношений «Один-к-Одному» (полиморфное)

Отсоединение связи «Один-к-Одному» (полиморфное)

Получение данных «Один-к-Одному» (полиморфное)

Удаление данных «Один-к-Одному» (полиморфное)

Один ко многим (полиморфное)

Миграции для моделей

Операции с данными идентичны обычным (не полиморфным) связям

Многие ко многим (полиморфное)

Миграции для моделей

Операции с данными идентичны обычным (не полиморфным) связям

Last updated