i tried to upload more than one image in database by doing this in controller:
public function store(request $request) {
$pictures=[];
$input=$request->all();
if($file=$request->file('images')) $pictures[]=$request->file('images');
if($file=$request->file('image1')) $pictures[]=$request->file('image1');
if($file=$request->file('image2')) $pictures[]=$request->file('image2');
if($file=$request->file('image3')) $pictures[]=$request->file('image3');
if($file=$request->file('image4')) $pictures[]=$request->file('image4');
if($file=$request->file('image5')) $pictures[]=$request->file('image5');
if($file=$request->file('image6')) $pictures[]=$request->file('image6');
foreach($pictures as $file)
for($name=0;$name<=7;$name++)
{
$name=$file->getClientOriginalName();
}
$file->move('image',$name);
$input['images']=$name;
$input['image1']=$name;
$input['image2']=$name;
$input['image3']=$name;
$input['image4']=$name;
$input['image5']=$name;
$input['image6']=$name;
Detail::create($input);
return redirect('/');
}
It takes images form form and stores the selected images in public/image folder but in database it stores all the images with same image name. and while displaying also it displays the same image many time.
I know guys here have solution to this and may have better idea. so please help me out in this. thanks in advance.
The above done method was not appropriate for me so i did this in my controller
public function uploadSubmit(request $request)
{
// Coming soon...
$data=$request->all();
$imagename =[];
$i = 0;
$files =Input::file('images');
foreach($files as $file){
$extension = $file->getClientOriginalExtension();
$imagename[$i] = 'post'.str_random(10).'.jpg';
$destinationPath = 'assets/posts';
$file->move($destinationPath, $imagename[$i]);
$i++;
}
Detail::create($files);
return redirect('/');
}
And in route:
Route::resource('/details','DetailController');
Now i am getting an error like this:FatalThrowableError in DetailController.php line 43: Call to a member function getClientOriginalName() on array. Can anyone point the problem here. thanks.