mardi 25 août 2015

unique name rule validation based on pivot table laravel

I have a system where renting companies have cars. A car can be available in many renting companies. So it is a many-to-many relationship.

I want to provide the companies with the possibility to add new cars when they buy them. If the car already exists, the system wouldn't create it, but flash an error message saying they already have that car.

How to use the unique validation rule on the name field of the Car being added? The challenge is that the Car model doesn't have the id of the company, and the pivot table doesn't have the name of the car, it contains just the car_id and the company_id.

Many thanks



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1hYvDHx
via IFTTT

Aucun commentaire:

Enregistrer un commentaire