Support the ongoing development of Laravel.io →
posted 8 years ago
Architecture

I have a tables user_id and event_id, every user can be added to every event, but how can I prevent that one user cannot be more times in the same event?

Example:

user_id event_id

3 1 -> ok

4 1 -> ok

3 1 -> not ok because the user is already added in line 1...

Is it to set in migration something?

Last updated 2 years ago.
0

Hi!

I guess you have to set multiple unique columns. You can do it with unique or primary property.

$table->unique(array('mytext', 'user_id'));
$table->primary(['first', 'second']);

Like they said here:

http://stackoverflow.com/questions/20065697/schema-builder-laravel-migrations-unique-on-two-columns

0

@ttimot24 fantastic laravel support, many thanks friend :)

$table->unique(array('mytext', 'user_id'));
Last updated 8 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

erdely erdely Joined 7 Nov 2016

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.