I searched before posting and I found this
Preventing Laravel adding multiple records to a pivot table
However if I try that solution I got an exception regarding query builder use of contains()
I need to check if an item is already attached to a user in the pivot table so to prevent multiple posts:
this one is the line I tried:
if (!Auth::user()->collected_item()->contains($id)) {
Auth::user()->collected_item()->attach($id);
}
but as said that doesn't work. So I built a query to check if the line user_id / id exists already in db, if resulting var is empty attach item else print "already there".. this way works however can it be simplified?