Add Current User to Pivot on save.
I have a Dealership model and the standard User model setup as a belongsToMany with a pivot table. Very basic, but what I am having issues with is when a user creates a new dealership I want to automatically add the user to the pivot table. Prior to having it a belongsToMany it was a hasMany dealerships so I used a boot method on the Dealership model to add the current user_id to the newly created dealership on save, which worked just fine using:
This is what I currently have for adding user/dealership to the pivot table:
I noticed that if I change from "created" to "saved", then create a new dealership then click the "save changes" button after the dealership has been created it will add the relationship, I just cannot get it to add the relationship on creation.
Any help would be appreciated!
Thanks
1 Reply
Fixed by adding the following to the "CreateDealership" page: