Laravel Redirect To Another URL / Web Page - HTTP Laravel Redirects

PHP Laravel 5.6 Image Upload with Validation Example

Today, We want to share with you PHP Laravel 5.6 Image Upload with Validation Example.In this post we will show you Image Upload with Validation in PHP Laravel 5.6, hear for Example of File Upload with Validation in Laravel 5.6 we will give you demo and example for implement.In this post, we will learn about File Upload with Validation in Laravel 5.6 with an example.

PHP Laravel 5.6 Image Upload with Validation Example

There are the Following The simple About PHP Laravel 5.6 Image Upload with Validation Example Full Information With Example and source code.

As I will cover this Post with live Working example to develop laravel 5.6 image upload with validation, so the some major files and Directory structures for this example is following below.

  • Setup laravel 5.6 upload image
  • Add Laravel 5.6 Routes
  • Create New Laravel 5.6 Controller
  • Create Laravel 5.6 Blade File
  Query Scope using Laravel 6 Eloquent Example

Step 1 : Setup Laravel 5.6 Web Application

Create Laravel 5.6 version application New Project

//laravel 5.5 image upload create New Project
composer create-project --prefer-dist laravel/laravel fileimgupload

Step 2: Include Images Laravel 5.6 Routes

routes/web.php

Route::get('image-upload',['as'=>'image.upload','uses'=>'[email protected]']);

Route::post('image-upload',['as'=>'image.upload.post','uses'=>'[email protected]']);

Step 3: Make New Laravel Controller

upload image laravel 5.6 Controller -> app/Http/Controllers/fileUploadController.php

<?php
//upload image laravel 5.6 Source code
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class fileUploadController extends Controller
{
    public function fileUpload()
    {
        return view('fileUpload');
    }

    public function fileUploadPost()
    {
        request()->validate([
            'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
        ]);
        $fileName = time().'.'.request()->image->getClientOriginalExtension();
        request()->image->move(public_path('images'), $fileName);
        return back()
            ->with('success','We have Good successfully upload files/image.')
            ->with('image',$fileName);
    }
}

Step 4: Make Blade File

Now, Final step You Need to Make a PHP fileUpload.blade.php file as well as in this simple blade file we will make a form with some HTML file input button. Therefor copy and paste bellow laravel 5.6 image upload source code and put on that your blade file.

  How to integrate CardConnect payment Gateway with Node JS

resources/views/fileUpload.blade.php

<!DOCTYPE html>
<html>
<head>
    <title>PHP Laravel 5.6 Image Upload with Validation Example</title>
    <link rel="stylesheet" href="http://getbootstrap.com/dist/css/bootstrap.css">
</head>
<body>
<div class="pakainfo container">
    <div class="panel panel-success">
      <div class="panel-heading"><h2>PHP Laravel 5.6 Image Upload with Validation Example</h2></div>
      <div class="panel-body">
        @if ($message = Session::get('success'))
        <div class="alert alert-success alert-block">
            <button type="button" class="pakainfo close" data-dismiss="alert">×</button>
                <strong>{{ $message }}</strong>
        </div>
        <img src="uploads/{{ Session::get('image') }}">
        @endif
        @if (count($errors) > 0)
            <div class="alert alert-danger">
                <strong>Sorry!</strong> There were some Any problems with your File/images.
                <ul>
                    @foreach ($errors->all() as $error)
                        <li>{{ $error }}</li>
                    @endforeach
                </ul>
            </div>
        @endif

        {!! Form::open(array('route' => 'image.upload.post','files'=>true)) !!}
            <div class="row">
                <div class="pakainfo col-md-6">
                    {!! Form::file('image', array('class' => 'form-control')) !!}
                </div>
                <div class="pakainfo col-md-6">
                    <button type="submit" class="btn btn-success">File Upload</button>
                </div>
            </div>
        {!! Form::close() !!}
      </div>
    </div>
</div>
</body>
</html>

Angular 6 CRUD Operations Application Tutorials

Read :

  Angular 6 Responsive Admin Themes & Templates free download

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about PHP Laravel 5.6 Image Upload with Validation Example.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.