check out updateOrCreate()
https://laravel.com/docs/5.3/eloquent#other-creation-methods
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi
I'm working on a voting system. I've these three tables/models.
The user can vote once on each voting.
If the user hasn't vote, it should create a new entry in the UserVoting with user-id, voting-id and the users vote.
If the user already voted on a voting, it should update the UserVoting entry.
I know there are many ways to do that. But what would be a very clean variant?
Regards,
check out updateOrCreate()
https://laravel.com/docs/5.3/eloquent#other-creation-methods
Please or to participate in this conversation.