我有2个字段来检查验证...
if(parent == 0)
return 'tag is required';
else
return 'tag can be nullable';
我想要这样的事情:
'parent' => 'nullable|numeric',
'tags' => 'required_with:parent=0|array|max:8',
我尝试这样的事情,但这是错误的:
General --->
Request URL:http://localhost/songs/album/album_1085/song_Ma%20Cherie%20Je%20T'aime_1425654205.mp3
Request Method:GET
Status Code:206 Partial Content
Remote Address:[::1]:80
Referrer Policy:no-referrer-when-downgrade
Response Headers --->
view source
Accept-Ranges:bytes
Cache-Control:max-age=7776000
Connection:Keep-Alive
Content-Length:4975034
Content-Range:bytes 0-4975033/4975034
Content-Type:audio/mpeg
Date:Wed, 27 Dec 2017 17:24:22 GMT
ETag:"4be9ba-560a79f00fbc0"
Expires:Tue, 27 Mar 2018 17:24:22 GMT
Keep-Alive:timeout=5, max=100
Last-Modified:Tue, 19 Dec 2017 01:45:27 GMT
Server:Apache/2.4.28 (Unix) PHP/5.6.31
Request Headers --->
view source
Accept:*/*
Accept-Encoding:identity;q=1, *;q=0
Accept-Language:en-US,en;q=0.9,fr;q=0.8
Cache-Control:no-cache
Connection:keep-alive
Cookie:remember_82e5d2c56bdd0811318f0cf078b78bfc=eyJpdiI6...(skipped); XSRF-TOKEN=eyJpdiI6...(skipped)
Host:localhost
Pragma:no-cache
Range:bytes=0-
Referer:http://localhost/song/Ma+Cherie+Je+T%27aime.54451502
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36
答案 0 :(得分:3)
使用required_if
规则。
如果anotherfield字段等于任何值,则验证字段必须存在且不为空。
'parent' => 'nullable|numeric',
'tags' => 'required_if:parent,0|array|max:8',