
我在数据库中存储多个图像作为array.but,如果我没有选择任何图像,它在数据库中存储null,这也是以数组形式。如何将其更改为“NULL”。

查看刀片:
@foreach($reply['image'] as $imagePath)
<img src="/image/{{ $imagePath }}"
style="width:150px; height:150px;">
@endforeach上传图片:
<div class="form-group">
<label class="control-label col-sm-2" >Image:</label>
<form action="upload" id="upload" enctype="multipart/form-data">
<input type="file" name="image[]" id="image" multiple><br />
</form>
</div>发布于 2018-02-04 05:33:50
您可以简单地检查数组元素是否为空。
@if(!$imagePath->isEmpty())
<img src="/image/{{ $imagePath }}"
style="width:150px; height:150px;">
@else在这里,如果图像不可用,您可以添加默认图像并在else if语句中使用。
您也可以使用is_null()代替isEmply()。
发布于 2018-02-04 20:29:15
或者,您可以在迁移中简单地使用以下代码:
$table->string('image')->default(NULL);然后,在查看视图时,只需执行以下操作
@if(!$imagePath)
No Image! (or default image path)
@else
(image display)
@endifhttps://stackoverflow.com/questions/48600542
复制相似问题