【发布时间】:2021-02-02 11:08:19
【问题描述】:
我在 Laravel-5.8 中有一个项目,用于上传 excel 和图像等文件。
我已成功插入。我将文件名保存在表中,并将文件本身保存在 a 中。我遇到的问题是如何在编辑视图刀片中检索文件。
控制器
public function update_employee_mid_year_comment(UpdateSelfReviewRequest $request, $id) {
$goal = Goal::find($id);
$goal->employee_mid_year_comment = $request->employee_mid_year_comment;
if ($request->employee_mid_year_attachment != "") {
$employee_mid_year_attachment = $request->file('employee_mid_year_attachment');
$new_name = rand() . '.' . $employee_mid_year_attachment->getClientOriginalExtension();
$employee_mid_year_attachment->move(public_path('storage/documents/mid_year'), $new_name);
$goal->employee_mid_year_attachment = $new_name;
}
$goal->save();
DB::commit();
Session::flash('success', 'Comment is Successfully Updated');
return redirect()->back();
}
我使用的是模态形式:
edit.blade
<div class="modal fade" id="edit{{ $goal->id }}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<form action="{{route('mid_year_setups.update_employee_mid_year_comment',['id'=>$goal->id])}}" method="post" enctype="multipart/form-data" id="edit_comment-form">
{{ csrf_field() }}
<div class="modal-header">
Update Self-Review Comment
</div>
<div class="col-md-12">
<div class="form-group">
<label class="control-label">Comment:<span style="color:red;">*</span></label>
<textarea rows="2" name="employee_mid_year_comment" class="form-control" placeholder="Enter Comment here" value="{{old('employee_mid_year_comment',$goal->employee_mid_year_comment)}})}}" required data-validation-required-message="This field is required">{{old('employee_mid_year_comment',$goal->employee_mid_year_comment)}}</textarea>
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<label class="control-label"> Attachment:</label>
<div class="custom-file">
<div class="custom-file">
<input value="{{old('employee_mid_year_attachment',$goal->employee_mid_year_attachment)}}" type="file" name="employee_mid_year_attachment" class="custom-file-input" id="customFile">
<label class="custom-file-label" for="exampleInputFile">Choose file</label>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="submit" id="edit_comment_btn-submit" class="btn btn-success btn-ok">Save</button>
</div>
</form>
</div>
</div>
</div>
文件名为employee_mid_year_attachment,路径为:storage/documents/mid_year
当我渲染编辑视图刀片时,它没有检索到附加的文档。我如何做到这一点?
谢谢
【问题讨论】:
-
您是要实际编辑文件,还是只编辑数据库行的值?
-
@Ballard - 我想显示文件名及其扩展名。我对编辑文本输入和其他没有问题。就像那里显示的文本输入一样。但它没有显示附件的任何内容
标签: laravel