Laravel 7 Crop Image Before Upload in Controller

In this tutorial you will learn about the Laravel 7 Crop Image Before Upload in Controller and its application with practical example.

In this laravel crop image before upload tutorial, I’ll show you how to crop image before upload in laravel. In this tutorial you will learn to crop image before upload in laravel using using jquery copper js. In this article I’ll demonstrate to crop and upload image in laravel using jquery copper js. In this example will store cropped image in the folder and later save it into database.

In this step by step guide we will be using cropper js to crop the image before uploading using bootstrap model. In this example We will be using crop the image will be in bootstrap model. Then we will also use the bootstrap model in which the preview of the image will also be shown.

Laravel 7 Crop Image Before Upload in Controller

  • Step 1: Install New Laravel App
  • Step 2: Add Database Details
  • Step 3: Create Migration & Model
  • Step 4: Add Route
  • Step 5: Create Controller By Artisan
  • Step 6: Create Blade View
  • Step 7: Make Upload Directory
  • Step 8: Start Development Server

Step 1: Install New Laravel App

First of all we need to create a fresh laravel project, download and install Laravel using the below command

Step 2: Add Database Details

Now, lets create a MySQL database and connect it with laravel application. After creating database we need to set database credential in application’s .env file.

Step 3: Migration & Model

Now, in this step we will create model and migration file. Please run the following command:

This command will create one model name Picture and also create one migration file for the Pictures table. Now, Navigate to database/migrations folder and open create_pictures_table.php file. And add the following code into it:

Now, run the migration to create database table using following artisan command:

Step 4: Add Routes

After this, we need to define routes in “routes/web.php” file. Lets open “routes/web.php” file and add the following routes in it.

routes/web.php

Step 5: Create Controller By Artisan

Now, lets create a controller named CropImageController using command given below –

Then, Navigate to app/http/controllers folder and open CropImageController.php file. Then put the following code into your laravel CropImageController.php file:

Step 6: Create Blade view

In this step,we will create a blade view file named crop-image-upload.blade.php file. Go to resources/views folder and create a file name crop-image-upload.blade.php. Then put the following code into the crop-image-upload.blade.php file:

Note that, you need to include the below following javascript cropper js library into your crop-image-upload.blade.php file:


Then, include the following script code into your crop-image-upload.blade.php file:


Here, the full source code of crop-image-upload.blade.php file with all javascript libraries, script code and css code:

Step 7: Make Upload Directory

In this step, navigate to your laravel project root directory and open public directory. Inside public directory, create one new directory name upload.

Step 8: Start Development Server

Now we are ready to run our example so lets start the development server using following artisan command –

Now, open the following URL in browser to see the output –

In this tutorial we have learn about the Laravel 7 Crop Image Before Upload in Controller and its application with practical example. I hope you will like this tutorial.