laravel - 如何使用 Laravel 检索上传的文件编辑视图刀片
问题描述
我在 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();
}
我正在使用模态形式:
编辑刀片
<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
当我渲染编辑视图刀片时,它没有检索到附加的文档。我如何实现这一目标?
谢谢
解决方案
在文件的值输入路径中使用
<input
value="{{asset('storage/documents/mid_year/'.$goal>employee_mid_year_attachment')}}"
type="file" name="employee_mid_year_attachment" class="custom-file-input"
id="customFile">
推荐阅读
- java - Java中类型对象的ArrayList - 我似乎无法弄清楚的错误
- android - 如何在 Android 中获取外部 USB 大容量存储路径?
- mysql - SQL:需要在 MySQL 中的相关表之间按优先级获取聚合状态
- c# - 与 TPT 代码优先实体框架中的引用约束冲突
- c# - 无法解析程序集:“ImageCircle.Forms”
- php - 如何从 AWS API 网关发送压缩的 API json 响应
- c++ - 包含时与 Qt 冲突的 Spinnaker
- corda - 在 Corda 中,如何获取交易发生时间的时间戳?
- drupal - 如何绕过 URL 上的高级 css/js 聚合
- gcc - gcc:无法识别的选项`-nolibc`