我很难更新和替换多个图像。我理解如何保存多个图像,但我无法更新和删除旧图像。
HTML表单更新
{!! Form::model($portfolio, ['route' => ['portfolio.update', $portfolio->id], 'method' => 'PUT', 'files' => 'true' ]) !!}
<input type="file" id="portfolio_photos" name="portfolio_photos[]" class="form-control" multiple>
{{!! Form::close() !!}}
控制器,我不知道如何更新方法。
public function store(PortfolioValidation $request){
$portfolio = new Portfolio();
$portfolio->portfolio_title = $request->portfolio_title;
$portfolio->portfolio_slug = str_slug($request->portfolio_title);
$portfolio->apartment_project = $request->apartment_project;
$portfolio->apartment_area = $request->apartment_area;
$portfolio->type_repair = $request->type_repair;
$portfolio->year_implementation = $request->year_implementation;
$portfolio->deadline = $request->deadline;
$portfolio->save();
if($request->hasFile('portfolio_photos')){
foreach($request->portfolio_photos as $portfolio_photo){
$fileName = rand() . '.' . $portfolio_photo->getClientOriginalExtension();
$path = public_path('img/portfolio/' . $fileName);
Image::make($portfolio_photo)->resize(1280, 960)->save($path);
$newFile = new Photo();
$newFile->portfolio_photos = $fileName;
$newFile->save();
$portfolio->photos()->save($newFile);
}
}
Session::flash('success', 'Success!');
return redirect()->route('portfolio.index');
}