gpt4 book ai didi

laravel - 验证前修改请求响应,Laravel

转载 作者:行者123 更新时间:2023-12-04 10:28:13 24 4
gpt4 key购买 nike

我从响应中得到一个 formData,我将其更改为中间件以在验证中使用它,问题是我必须进行另一次修改以验证数组中的所有元素而不使用“”阵列 .oneElement'。

来自中间件的代码

public function handle($request, Closure $next)
{
if ($request->has('all_values')) {
$request->merge([
'all_values' => json_decode($request->get('all_values'), true)
]);
}

return $next($request);
}

//来自请求
public function rules()
{
$validations = [
'all_values.saleforce_id' => 'required',
'all_values.customer_id' => 'required',
'all_values.lkp_product_category_id' => 'required',
]
// I need to access this all_values before validations

if (request()->has('validation_field')) {
return [request()->validation_field => $validations[ request()->validation_field ]];
} // this is used for a validation , to do validation onChange

return $validations;
}


$request = $request->all()['all_values']; // I need something like this, but this doesn't work

最佳答案

FormRequests您可以使用 prepareForValidation() .

protected function prepareForValidation()
{
$this->merge([
'all_values' => json_decode($request->get('all_values'), true),
]);
}

关于laravel - 验证前修改请求响应,Laravel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60542202/

24 4 0
文章推荐: ms-access - SQL 查询中表名中的减号/连字符
文章推荐: html - BeautifulSoup : extracting from deeply nested
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com