-
I would like to know why all the required data cannot be inserted in the database table name - products. I am now experiencing this problem. I cannot upload pictures:
In Controller
public function postCar(Request $request){ $this->validate($request, [ 'repo_yard' => 'required', 'status' => 'required', 'img' => 'required', 'img' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048' ]);
Upload image same controller
$ads = new Product; $images = $request->file('img'); $count = 0; if($request->file('img')){ foreach($images as $item){ if($count < 4){ $var = date_create(); $date = date_format($var, 'Ymd'); $request->img->storeAs('public/uploads'); $imageName = $date.'-'.$item->getClientOriginalName(); $item->move(public_path().'/uploads/',$imageName); $url = URL::to("/").'/uploads/'.$imageName; $arr[] = $url; $count++; } } $image = implode(",", $arr); $ads->status = $request->input('status'); $ads->image = $image; $ads->save(); return redirect('/')->with('info', 'Product published successfully.'); } }
In blade.php
<div class="col-lg-12"> @if(session('info')) <div class="alert alert-success" style="margin-top: 5px;"> </div> @endif </div>
another blade.php
<div class="col-lg-6"> <div class="col-lg-12"> <div class="form-group"> <label><strong>Photos of your vehicle (Max 4)</strong></label> <input type="file" class="form-control" name="img[]" multiple=""/> </div> </div> <label></label> @if($errors->has('img')) <span class="alert alert-danger" style="margin-left:13px; padding:5px;"></span> @endif </div> </div>
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire