Multiple Images File Upload Using Laravel 5.6 Or Laravel 5.7

Upload Multiple Images in Laravel 5.6 Or Laravel 5.7, Laravel 5.6 Or Laravel 5.7 Multiple Images File Upload, Upload Multiple Images Files with Validation in Laravel 5.6 Or Laravel 5.7

Hello Friends, Today I will tell you through this tutorial how do you upload multiple image files through Laravel 5.6 Or Laravel 5.7. So we will learn step-by-step in Laravel 5.6 Or Laravel 5.7.

Step 1: – In Laravel 5.6 Or Laravel 5.7 You First create a form and take a field input type file in it. Just like the lower form has been created. You can also copy this form.

resources/views/multipleimagefile.blade.php

<!DOCTYPE html>
<html>
<head>
<title>Laravel 5.6 Or Laravel 5.7 Multiple Image File Upload</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css">
</head>
<body>
<form method="post" action="{{url('multiplefileupload')}}" enctype="multipart/form-data">
<input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">
<div class="col-md-12">
<div class="form-group">
<label for="">Multiple File Select</label>
<input required type="file" class="form-control" name="images[]" multiple>
</div>
</div>
<div class="col-md-6">
<div class="box-footer">
<button type="submit" class="btn btn-primary">Save</button>
</div>
</div>
</form>
</body>
</html>

Routes/web.php

Step 2: – In this step, when we select the file, submit the data by post method. So in the web.php file, the url of post method will be given in this way. And add this url to the controller.

Route::get('multipleimagefile', function () {
return view('multipleimagefile');
});
Route::post('multiplefileupload', 'multipleimageController@multiplefileupload');

multipleimageController.php

Step 3: – Now we will create this one controller and keep this controller’s name as multipleimageController.php. Then after that we will write the code to upload multiple image file in these controller. How to upload multiple image files in Laravel 5.6 Or Laravel 5.7.  You can see the code in this controller.

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use DB;
use Validator;
use Redirect;
use View;
class multipleimageController extends Controller
{
public function multiplefileupload(Request $request)
{
$images=array();
if($files=$request->file('images')){
foreach($files as $file){
$name=$file->getClientOriginalName();
$file->move('image',$name);
$images[]=$name;
/*Insert your data*/
DB::table('blog')->insert([
'image' => $name
]);
/*Insert your data*/
}
}
return redirect()->back()->with('message', 'Successfully Save Your Multiple Images file.');
}
}