我有问题,我正在编写功能来编辑列表菜单,当我尝试更新文件图像然后我遇到getClientOriginalName()中的错误
在数组
上调用成员函数getClientOriginalName()
@foreach($edits as $key => $value)
<input type="hidden" value="{{ $key }}" name="key_edit[{{ $key }}]">
<div class="col-md-10">
<div class="col-md-6">
<div class="form-group">
<label class="form-label" for="field-4">Tên menu</label>
<span class="desc">vd "Technology"</span>
<div class="controls">
<input type="text" id="field-4" name="menu_title[{{ $key }}]" placeholder="Vui lòng điền tên" class="form-control"
value="{{ $value->menu_title }}">
<input type="hidden" id="field-4" name="id_menu[{{ $key }}]" placeholder="Vui lòng điền tên" class="form-control"
value="{{ $value->menu_id }}">
</div>
</div>
</div>
<div class="col-md-6">
<div class="col-md-10 ">
<div class="form-group">
<label class="form-label" for="formfield10">Icon menu</label>
<span class="desc">vd. "character.jpg"</span>
<div class="controls">
<input type="file" multiple="{{ $key }}" class="form-control" id="formfield10" name="upload_icon[{{ $key }}]">
<input type="hidden" value="{{ $value->icon }}" name="icon_hidden[{{ $key }}]">
</div>
</div>
</div>
</div>
</div>
<div class="col-md-2">
<div class="col-md-1 btn-iconic">
<div style="height:33px"></div>
<div class="controls">
<button type="submit" class="btn btn-purple pull-right"><i class="fa fa-edit "></i></button>
</div>
</div>
<div class="col-md-1 btn-iconic">
<div style="height:33px"></div>
<div class="controls">
<button type="submit" class="btn btn-purple"><i class="fa fa-close "></i></button>
</div>
</div>
</div>
@endforeach
</form>
MenuController
public function edit(Request $request){
$input= $request->all();
$edit = DB::table('categorys')->get();
if($request->hasFile('upload_icon')) {
$file = $input['upload_icon'];
$name = $file->getClientOriginalName();
$file->move(public_path().'/images/menu', $name);
$id= $request->input('id_menu');
$name = $request->input('menu_title');
$icon= $name;
foreach ($edit as $key => $value) {
DB::table('categorys')->where('menu_id', $id)->update([
'menu_id'=> $id[$key],
'menu_title' => $name[$key],
'icon' => $icon[$key]
]);
}
}
else{
$id= $request->input('id_menu');
$name = $request->input('menu_title');
$icon= $request->input('icon_hidden');
$key =$request->input('key_edit');
foreach ($edit as $key => $value) {
DB::table('categorys')->where('menu_id', $id)->update([
'menu_id'=> $id[$key],
'menu_title' => $name[$key],
'icon' => $icon[$key]
]);
}
}
return View('admin.menu.edit')->with('edits',$edit);
}
DD($输入[&#39; upload_icon&#39;]);
array:2 [▼
0 => UploadedFile {#161 ▼
-test: false
-originalName: "life_icon_post.png"
-mimeType: "image/png"
-size: 344
-error: 0
path: "E:\xampp\tmp"
filename: "phpB451.tmp"
basename: "phpB451.tmp"
pathname: "E:\xampp\tmp\phpB451.tmp"
extension: "tmp"
realPath: "E:\xampp\tmp\phpB451.tmp"
aTime: 2016-05-20 10:40:16
mTime: 2016-05-20 10:40:16
cTime: 2016-05-20 10:40:16
inode: 0
size: 344
perms: 0100666
owner: 0
group: 0
type: "file"
writable: true
readable: true
executable: false
file: true
dir: false
link: false
linkTarget: "E:\xampp\tmp\phpB451.tmp"
}
1 => null
]
答案 0 :(得分:2)
您似乎正在尝试在收集时使用方法。您应该使用foreach()
来迭代文件,或者如果您只有一个文件,请执行以下操作:
$name = $file[0]->getClientOriginalName();