php - 验证来自 foreach Laravel 的汇总数组字段
问题描述
目前,我foreach array
在收集所有tasks
内容并包含weight
每个任务的地方工作。
这是我的工作代码
foreach ($arr4 as $row4) {
$taskCode = strtoupper(str_random(12));
$insert_data5[] = array(
'projCode' => $projCode,
'taskCode' => $taskCode,
'taskWeight' => $row4['weight'],
'plan_days' => $row4['planned_days'],
'actual_days' => $row4['actual_days'],
'deleted' => 0,
'by_id' => auth()->user()->id,
'updated_by' => auth()->user()->name,
'created_at' => now(),
'updated_at' => now(),
);
}
dd($insert_data5);
输出
我要做的是验证总和taskWeight
是否5 Tasks
未达到 100%,这将显示一条错误消息。
截至目前我的想法是使用validator
,但我不知道如何计算数组字段taskWeight
$validator = Validator::make(
$insert_data5,
[
......
]
);
if($validator->fails()){
return redirect()
->back()
->with(['errors'=>$validator->errors()->all()])
->with('modal',$modal);
}
解决方案
推荐阅读
- laravel - Vue Routing 是否可用于使用 laravel 构建复杂的基于目录的应用程序
- django - 浏览器抱怨访问控制标头丢失,即使它在那里
- python - 使用 python 调用 SAS 脚本 - 子进程
- c# - 使用 EWS 保存约会会导致 System.ArgumentException:已添加具有相同键的项目。钥匙:Dlt/1916
- ios13 - iOS 13 中的 CallKit:如何延迟响铃?
- wordpress - WordPress、Git 和 Docker
- python - 只有最后一行被添加到数据框中
- conda - Tensorflow 失败,因为它在 conda 环境中没有写权限
- c++ - glGetFloatv 导致堆栈粉碎
- android - 如何使用从适配器传递的 url 下载图像