Php 现有图像未以编辑形式显示,无法在larvel(5.8)中更新
我试图制作todo列表,其中显示更新表单其他字段值,但对于图像,该值从文件夹中读取,但不显示在输入字段中 除了这个问题,一切都正常 这将显示图像名称Php 现有图像未以编辑形式显示,无法在larvel(5.8)中更新,php,image,laravel-5,upload,Php,Image,Laravel 5,Upload,我试图制作todo列表,其中显示更新表单其他字段值,但对于图像,该值从文件夹中读取,但不显示在输入字段中 除了这个问题,一切都正常 这将显示图像名称 我使用dd($task->img”)以检查值 edit.blade.php <label for="title">Task Title</label> <input type="text" value="{{$task->title}}" class="form-control"
我使用dd($task->img”)代码>以检查值
edit.blade.php
<label for="title">Task Title</label>
<input type="text" value="{{$task->title}}" class="form-control" id="taskTitle" name="title" >
</div>
<div class="form-group col-6">
<label for="description">Task Description</label>
<input type="text" value="{{$task->description}}" class="form-control" id="taskDescription" name="description" >
</div>
<div class="form-group col-6">
<label for="img">Task Image</label>
<input type="file" value="{!! $task->img !!}" class="form-control" id="taskImg" name="img" >
</div>
添加文件作为默认值对输入字段不起作用。
您可能希望在输入字段上方添加一个额外的div,如:
<div>
<p>Current image</p>
<img src="{!! asset($task->img) !!}">
<p>Upload new image:</p>
<div class="form-group col-6">
<label for="img">Task Image</label>
<input type="file" class="form-control" id="taskImg" name="img" >
</div>
</div>
我忘了包括enctype=“multipart/form data”,还有这个错误,您会发现的。谢谢您的回答。
<div>
<p>Current image</p>
<img src="{!! asset($task->img) !!}">
<p>Upload new image:</p>
<div class="form-group col-6">
<label for="img">Task Image</label>
<input type="file" class="form-control" id="taskImg" name="img" >
</div>
</div>
$path = $request->file('img')->store('images');
$task->img = $path;