当我上传文件时,我将错误视为标题。 但如果我没有上传文件,验证就可以了。 我还检查了$ request,但我仍然不知道是什么问题。
这是我的$ smreenshot请求 $request
这是我的代码
$rules = [
'edu_title' => 'max:255',
'edu_author' => 'max:10',
'categories' => 'max:100',
'file_name' => 'nullable|file',
'updated_at' => 'date|before:tomorrow'
];
$messages = [
'required' => '此欄位必填',
'max' => '此欄位最大長度必須小於 :max',
'date' => '請選擇日期',
'before' => '選擇的日期錯誤'
];
$validate = Validator::make($request->all(), $rules, $messages);
if($validate->fails()) {
return back()->witherrors($validate)->withInput();
}
$path = '';
if($request->hasFile('file_name')) {
$validate = Validator::make($request->file_name, ['file_name' => 'file']);
if( Storage::disk('local')->exists($directories.'/'.$file_name) ) {
return back()->with('file exists', '檔案已經存在或檔名重複')->withInput();
}
$path = $request->file('file_name')->storeAs(
$directories, $file_name);
}
OtherTeachingMaterial::find($id)->update([
'edu_title' => $request->edu_title,
'edu_author' => $request->edu_author,
'file_path' => $path,
'categories' => $request->categories,
'updated_at' => $request->updated_at
]);
return redirect()->route('others_teahcing_material.dashboard')->with('success', '更新成功');
答案 0 :(得分:1)
您可以将文件static T[,] CreateRectangularArray<T>(T[][] arrays)
{
// TODO: Validation and special-casing for arrays.Count == 0
int minorLength = arrays[0].Length;
T[,] ret = new T[arrays.Length, minorLength];
for (int i = 0; i < arrays.Length; i++)
{
var array = arrays[i];
if (array.Length != minorLength)
{
throw new ArgumentException
("All arrays must be the same length");
}
for (int j = 0; j < minorLength; j++)
{
ret[i, j] = array[j];
}
}
return ret;
}
添加到 string[][] allEvars = new string[evars.Count][];
for (var i = 0; i < evars.Count; i++) {
var evarsList = new List<string>();
evarsList.Add(evars[i].id.Value);
evarsList.Add(evars[i].name.Value);
if (evars[i].enabled != null)
evarsList.Add(evars[i].enabled.Value.ToString());
else
evarsList.Add("");
if (evars[i].description != null)
evarsList.Add(evars[i].description.Value);
else
evarsList.Add("");
string[] evarsArray = evarsList.ToArray();
//var range = (Excel.Range)wsEvars.Range[wsEvars.Cells[i + 5, 2], wsEvars.Cells[i + 5, evarsArray.Length]];
//range.Value = evarsArray;
allEvars[i] = evarsList.ToArray();
}
var range = (Excel.Range)wsEvars.Range[wsEvars.Cells[5, 2], wsEvars.Cells[allEvars.Length, 3]];
string[,] newallEvars = CreateRectangularArray<string>(allEvars); //added row
range.Value2 = newallEvars; // changed row
数组中,然后删除第二个rule
方法,以便{{1}数组将是:
$rules