自定义json数组验证规则
1.php artisan make:rule 名称
2.规则文件内容如下:
<?php
namespace App\Rules;
use Illuminate\Contracts\Validation\Rule;
use Illuminate\Support\Facades\Validator;
class JsonArray implements Rule
{
protected $rules;
protected $errorMessage;
/**
* Create a new rule instance.
*
* @return void
*/
public function __construct($rules)
{
$this->rules = $rules;
}
/**
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $json)
{
if(is_array($json)){
$list = $json;
}else{
$list = json_decode($json, true);
}
if (empty($list)) {
return true;
}
$result = $this->validatorJsonArray($list);
return $result;
}
/**
* json验证
* @param $da