Is there is a way of referencing another field when specifying the exists validation rule in Laravel? I want to be able to say that input a must exist in table a, input b must exist in table b AND the value for column x in table b must equal input a.
Best explained by example:
public $rules = array(
'game_id' => 'required|exists:games,id',
'team1_id' => 'required|exists:teams,id,game_id,<game_id input value here>',
'team2_id' => 'required|exists:teams,id,game_id,<game_id input value here>'
);
So with my validation rules I want to be able to make sure that:
game_id
exists within the games
table (id
field)
team1_id
exists within the teams
table (id
field) and the game_id
column (in the teams
table) must equal the value of the game_id
input.
- As above for
team2_id
So, if in my form, I entered 1
for game_id
, I want to be able to ensure that the record within the teams table for both team1_id
and team2_id
have the value 1
for game_id
.
I hope this makes sense.
Thanks
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…