Loyd
2 months ago
401
3
Laravel

Polymorphic Pivot Table

Posted 2 months ago by Loyd

I currently have posts that can be liked through a pivot table using the Laravel toggle method.

I now have comments and replies that I also want a user to like.

And having multiple tables is not the best option.

My post_user pivot currently looks like

public function up()
    {
        Schema::create('post_user', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('user_id');
            $table->unsignedBigInteger('post_id');
            $table->timestamps();
        });
    }

The question is how can I have a polymorphic pivot table for this scenario.

Am still in dev mode and can reconstruct.

Please sign in or create an account to participate in this conversation.