Have you tried adding a ->unique() flag to the userId field in your Project migration, so the Exception can be handled when it tries to insert a new record, and there is already one present?
relationship defined in the model alone does not actually handle this behavior. you can either check if a project exist before to creating one or add an index as @joshuaajones suggested, which will throw a mysql exception when trying to insert.
Dude you forgot the main part the best method is validation. Validate it using Request and use exists rule to achieve this.
Thanks
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community