我有一个属性广告,其中包含上传照片的字段。它似乎'上传它们没有错误,但我无法显示它们。我得到了丢失的图像图标。这是我的代码
FORM
<form method="POST" action="/property" enctype="multipart/form-data">
{{ csrf_field() }}
<div class="form-group row">
<label for="photo" class="col-md-3 col-form-label text-md-right">Images</label>
<div class="col-md-9">
<input required type="file" class="form-control" name="photo[]" placeholder="address" multiple>
</div>
</div>
</form>
存储控制器
public function store(Request $request){
$input=$request->all();
$images=array();
if($files=$request->file('photo')){
foreach($files as $file){
$name=$file->getClientOriginalName();
$file->move('photo', $name);
$images[]=$name;
}
}
$Advert = PropertyAdvert::create([
//"photo" => base64_encode(file_get_contents($request->photo->path())),
'photo'=> implode("|",$images),
"address" => $request->address,
"county" => $request->county,
"town" => $request->town,
"type" => $request->type,
"rent" => $request->rent,
"date" => $request->date,
"bedrooms" => $request->bedrooms,
"bathrooms" => $request->bathrooms,
"furnished" => $request->furnished,
"description" => $request->description,
"user_id" => Auth::id(),
]);
$id = $Advert->id;
return redirect("/property/$id");
}
有什么想法吗?
修改
这是迁移文件。如您所见,照片字段是第一个。
Schema::create('property_adverts', function (Blueprint $table) {
$table->increments('id');
$table->binary('photo');
$table->string('address');
$table->string('county');
$table->string('town');
$table->string('type');
$table->string('rent');
$table->string('date');
$table->string('bedrooms');
$table->string('bathrooms');
$table->string('furnished');
$table->longText('description');
$table->integer('user_id');
$table->timestamps();
显示页码
<div class="card-body col-md-12">
@foreach ($Advert as $Ad)
<img src="data:image/gif;base64,{{ $Ad['photo'] }}" class="img-fluid full-width col-md-12">
@endforeach
</div>