Laravel 5.如何使用'有时'请求中的验证规则?

时间:2015-05-08 21:17:19

标签: laravel laravel-5 laravel-validation

我正在使用位于App \ Http \ Requests文件夹中的Post *** Request.php。我有一个表格,只有当我的用户进入他的国家巴基斯坦时我才想要城市领域。否则这些字段可以为空白。

    $city1Rule = 'required_without_all:city1,city2,city3|different:city2|different:city3|in:'.implode (",", $cities);

    $city2Rule = 'required_without_all:city1,city2,city3|different:city1|different:city3|in:'.implode (",", $cities);

    $city3Rule = 'required_without_all:city1,city2,city3|different:city2|different:city1|in:'.implode (",", $cities);

    return [
        'country' => 
        'city1' => $city1Rule,
        'city2' => $city2Rule,
        'city3' => $city3Rule,
        'other_rules' => 'other_rules',         
        ];

我希望这项工作仅适用于此文件。我该如何修改它?

1 个答案:

答案 0 :(得分:3)

您可以使用required_if:

required_if:country,Pakistan