I'd use tiny integer with -1/1.
- You can run sum(vote) to get the total.
- I think it's conceptually clearer. The meaning of liked = 0 is not as obvious.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello
I have a question about 2 approaches of storing likes & dislikes in MySQL db
In this approach we will use true for likes and false for dislikes, if user wanna to remove his vote (unlike or undislike) we will delete record:
Schema::create('likes', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
$table->foreignId('recipe_id')->constrained()->cascadeOnDelete();
$table->boolean('liked'); // 1 => like | 0 => dislike
$table->timestamps();
$table->unique(['user_id', 'recipe_id']);
});
We will save the vote value in the vote field, where 1 will mean liked and -1 disliked. We will also set the value to 0 if a user removes any of the options.
Schema::create('votes', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
$table->foreignId('recipe_id')->constrained()->cascadeOnDelete();
$table->smallInteger('vote');
$table->timestamps();
});
"It always depends", but I would like to get your feedback
Would be grateful for your opinion
Best regards
Please or to participate in this conversation.