1
複数の画像をアップロードしてlaravel 5.3で表示する方法は?複数の画像をアップロードしてlaravel 5.3でどのように取得できますか?
私のコントローラの機能は次のとおりです。
public function newOffer(Request $request){
$validate_marge['img'] = 'required|image|mimes:png,jpg,jpeg';
$validator = Validator::make($request->all(), $validate_marge);
if ($validator->fails()){
return back()->withInput()->withErrors($validator);
}else{
$post = new Post();
if (Input::hasFile('img')){
$file = Input::file('img');
$file->move(public_path('img/offers').'/', $file->getClientOriginalName());
$post->img = $file->getClientOriginalName();
}
}
$post->title = Input::get('title');
$post->category_id = Input::get('category_id');
$post->second_title = Input::get('second_title');
$post->description = Input::get('description');
$post->location = Input::get('location');
$post->price = Input::get('price');
$post->save();
return back();
}
とあるHTMLの形式は次のとおりです。
<form class="form-horizontal" method="post" action="{{ url('newOffer') }}"
enctype="multipart/form-data">
{{ csrf_field() }} <div class="form-group">
<label class="col-md-4 control-label">Select IMG's</label>
<div class="col-md-6">
<input type="file" class="form-control" id="image"
name="images[]"
required
data-validation-required-message="Please choose image" multiple>
<p class="help-block">{{$errors->first('images')}}</p>
</div>
</div> <input type="submit" value="Add" class="btn btn-primary" style="width: 100%"></form>
私はそれを行うにはコントローラーに何をすべきかと私はポストにプレビューするか?? が
if (Input::hasFile('img')){
$files = Input::file('img');
foreach ($files as $file){
$file->move(public_path('img/offers').'/', $file->getClientOriginalName());
}
$post->img = $file->getClientOriginalName();
$post->title = Input::get('title');
$post->category_id = Input::get('category_id');
$post->second_title = Input::get('second_title');
$post->description = Input::get('description');
$post->location = Input::get('location');
$post->price = Input::get('price');
$post->save();
}
return back();
にあなたにすべて
アップロードしたファイルをループする必要がありますアップロード? –
フォームの属性を追加できますか? – wahdan
画像を保存するときにforeachを追加することはできますが、質問があります。それぞれの画像に同じ画像がありますか? – wahdan