I'm using required if in Laravel validation, but it doesnt work. what is my mistake?
public function rules()
{
if (!empty($this->game_id)) {
$game = Game::find($this->game_id);
$game_type = $game->type;
} else {
$game_type = 'sport';
}
return [
'game_id' => 'required',
'platform_id' => 'required_if:' . $game_type . ',==,electronic',
]
}
game_type
seems to be dynamic, make sure it's an valid input namegame_type
is equals toelectronic
.