Laravel 5.4 Upload Image with Validation example

Submitted by dave - 7 years ago

Laravel 5.4 Upload Image with Validation example


// Laravel 5.4 Upload Image with Validation example Controllers
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
class ImageUploadController extends Controller
{
    /**
    * Create view file
    *
    * @return void
    */
	// display upload-image page 
    public function getUploadImage()
    {
        return view('upload-image');
    }
    /**
    * Manage Post Request
    *
    * @return void
    */
	// get image from upload-image page 
    public function postUplodeImage(Request $request)
    {
        $this->validate($request, [
			// check validtion for image or file
            'uplode_image_file' => 'required|image|mimes:jpg,png,jpeg,gif,svg|max:2048',
        ]);
		// rename image name or file name 
        $getimageName = time().'.'.$request->uplode_image_file->getClientOriginalExtension();
        $request->uplode_image_file->move(public_path('images'), $getimageName);
        return back()
            ->with('success','images Has been You uploaded successfully.')
            ->with('image',$getimageName);
    }
}

// see more at :: http://www.onlinecode.org/laravel-5-4-upload-image-validation-example/