dimanche 20 septembre 2015

Laravel 5.1 INSERT if record exists in another table

Trying to get my first laravel applications finished, but since I'm quite new to it I cannot figure out a solution. What I need is for user to be able to insert a row to table "Y" only if table "X" has a row with the value users is trying to save. Quick exaple:

table X
----------------
name  |  idcode
----------------
john  |  12345(unique)
----------------
table Y
----------------
name  |  idcode
----------------
john  |  12345  <- user is able to save this row 
john  |  54321  <- user is not able to save this, since idcode does not
----------------   appear in table X

I'm able to do a check between two tables with unique index via request but that checks if idcode is in table X and if it is it won't let save in table Y. I could use and the same check but the other way around. Has anyone had any experience with this?

Cheers



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire