douxiyi2418 2018-10-05 17:46
浏览 1071
已采纳

验证字段:required_if url包含Laravel中的参数

Is there any way to validate required field when the requested url contains some parameter?

  • 写回答

2条回答 默认 最新

  • douwo5710 2018-10-05 17:49
    关注

    Assuming you are using Form requsts, you can simple use PHP condition.

    public function rules()
    {
        $rules = []; // here you put some rules
    
        // here you check condition and add some rule when it's true
        if (str_contains($this->input('url'), 'something')) {
           $rules['some_other_field'] = 'required';
    
        }
    
        return $rules;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?