What is the use of laravel morphs relationship

Here we will discuss morphs migration for creating morph relationship table column. laravel migration tutorials.

Laravel morphs migration

When we use laravel morph relationship, it required a table that contains one or more table relational data. This table has two columns one is biginteger which stores foreign key data and the other is varchar which has a related model path.

Now our morphs() migration method create these two column by one migration.

public function up()
{
    Schema::create('images', function (Blueprint $table) {
        $table->morphs('imageable');
    });
}

In above example morphs('imageable') method create two columns imageable_id(bigint) and imageable_type(varchar).

php laravel developer anmol sharma

Anmol Sharma

I am a software engineer and have experience in web development technologies like php, Laravel, Codeigniter, javascript, jquery, bootstrap and I like to share my deep knowledge by these blogs.

Random tutorial links