Step 1: Install Laravel 5.7 Project
To create a new Laravel 5.7 project, open your terminal or command prompt and run the following command:
Step 2: Database Configuration
After installation, configure your database connection in the .env file. Set the following environment variables for MySQL:
Ensure that your MySQL database is running and the database management_system exists.
Step 3: Define Routes
In routes/web.php, Define the routes for the user profile and avatar upload functionality:
This route will handle the avatar update functionality via a POST request.
Step 4: Create the HomeController
Now, create a controller HomeController.php where the logic for updating the user's profile picture will reside.
Run the following command to generate the controller:
Add the following methods to HomeController.php:
Step 5: Add Image Intervention Service Provider
Next, you need to add the Intervention Image package to handle image resizing and manipulation.
-
First, install the
Intervention Imagepackage via composer:
-
Register the service provider in
config/app.php:
-
Add the alias in the
aliasesarray:
This will enable the image manipulation functionality in your application.
Step 6: Frontend Form for Avatar Upload
Create a form in the frontend where the user can upload their avatar. For example, in resources/views/dashboard/index.blade.php:
This form will send the uploaded avatar to the update_avatar method in HomeController.
Step 7: Displaying the Avatar
In your view, you can display the user's avatar using the following:
Final Notes:
-
Ensure the public folder is properly configured to store and access the image files.
-
You can customize the validation rules and image resizing and save locations per your project’s requirements.
-
Ensure the proper setup of
storagesymlink if you're storing avatars in thestoragefolder by running:
This will make sure that your images stored in storage/app/public are publicly accessible.

