Laravel - Like \ Dislike system

Posted 1 year ago by Rainieren

Hello, I'm currently working on a project which requires the option to like and dislike posts and comments. Unfortunately, I don't know how to put this in my database migrations, and honestly, I don't know how to make this work either. But first I want to sort the database out so I can find it out myself. I have a posts migration which looks like this:

public function up()
    {
        Schema::create('posts', function (Blueprint $table) {
            $table->increments('id');
            $table->Unsignedinteger('user_id');
            $table->Unsignedinteger('channel_id');
            $table->string('post_title');
            $table->longText('post_text');
            $table->string('slug')->unique();
            $table->timestamps();
        });
    }

And I have a comments migration which looks like this:

public function up()
    {
        Schema::create('replies', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('user_id')->unsigned();
            $table->integer('post_id')->unsigned();
            $table->longText('reply_text');
            $table->timestamps();
        });
    }

They both can receive likes and dislikes. Later I want to make notifications out of these. So I need to get information about the user. Does anyone know how to make this work in the database? If I'm correct, I need a create_likes_table and create_dislikes_table?

I know I need a Likes and Dislikes model, but I'm not too sure. I ask because it defines the relations between the two. For instance: A comment can have many dislikes.

Does someone know how to achieve this. And is there maybe a great tutorial that can help me? Thanks in advance!

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

Reply to

Use Markdown with GitHub-flavored code blocks.