Php 如果不需要字段,则Laravel不进行验证
我已获得以下请求验证:Php 如果不需要字段,则Laravel不进行验证,php,laravel,validation,Php,Laravel,Validation,我已获得以下请求验证: <?php namespace App\Http\Requests; use Illuminate\Foundation\Http\FormRequest; class OwnerEstate extends FormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ p
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class OwnerEstate extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'firstname' => 'required_if:type,individual',
'secondname'=> 'required_if:type,individual',
'lastname' => 'required_if:type,individual',
'pin' => 'required_if:type,individual|digits:10',
'name' => 'required_if:type,legal-entity',
'eik' => 'required_if:type,legal-entity|digits:9'
];
}
}
数字:如果,则10
与必填项完全分开,因此它将验证该字段是否必填。但是,如果您还希望允许null或空值(假设该字段不是必需的),则可以添加规则nullable