I have a pivot table
id | product_id | user_id
I wish to update this pivot table, I do so by:
Product::find($productId)->attach($userId);
This will produce something like
id | product_id | user_id
1 1 1
But then when I do it again I do not want to update the pivot table if the values already exists.
The above attach method would do something like:
id | product_id | user_id
1 1 1
1 1 1
I know you can use sync, but this removes everything from the table, I do not wish to do this. I also know you can use:
Product::find(1)->user()->updateExistingPivot(1, []);
But this only works when data is in the table.
What Im looking for is a way to do firstOrCreate on a pivot table.