I'm trying to store multiple images in database and also show them in the view. I have products table and images table which are related, in the images table I have a foreign key named(image). So far it just store and show only one image instead of multiple.
Here are the codes
Controller
public function store(Request $request)
{
$formInput=$request->all();
$image=array();
if($files=$request->file('image')){
foreach($files as $file){
$name=$file->getClientOriginalName();
$file->move('images',$name);
$image[]=$name;
$formInput['image']=$name;
}
}
Blade
<input type="file" name="image[]" multiple class="form-control">
Product.php
public function products()
{
return $this->belongsTo('App\Images', 'image');
}
Images.php
public function images()
{
return $this->hasMany(Product::class, 'image');
}
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/31VFypn
via IFTTT
Aucun commentaire:
Enregistrer un commentaire