Laravel根据另一个领域的价值验证该领域

I want to validate two fields i.e. 'type' and 'options' where 'type' field is enum. The 'options' field should be validated only if the value of 'type' field is 'opt'.

$this->validate($request, [
    'type' => 'required|in:opt,number,text,file,image',
    'options'=>the condition I need(if type is 'opt')
]);

You can use required_if validation in Laravel.

$this->validate($request, [
    'type' => 'required|in:opt,number,text,file,image',
    'options'=> 'required_if:type,==,opt'
]);

Here is a Documentation link

You can add validation conditionally like this

$this->validate($request, [
        'type' => 'required|in:opt,number,text,file,image',
        'options'=>($input['type'] == 'opt')?'required':''
    ]);