DEV Community

Cover image for Laravel 8.0 Image Upload Example
devcse
devcse

Posted on • Edited on

Laravel 8.0 Image Upload Example

Hello artisan,

How are you? Today I am going to show you how to upload images in your Laravel project. In this tutorial, you can also upload your image reference to your database also. That means you can upload your image to the Database and also you can fetch images from your directory using DB image name reference.

Create a Laravel Project first, run this command
composer create-project --prefer-dist laravel/laravel blog
Make databse Connection , create a database in the Mysql database after that go to the .env file and set the values,

Make Database Connection and add the code to .env file

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel_crud
DB_USERNAME=root
DB_PASSWORD=

Enter fullscreen mode Exit fullscreen mode

Make your custom route,

routes/web.php

Route::get('/image/upload', [UploadImageController::class, 'imageUpload'])->name('image.upload.index');
Route::post('/image/upload/store', [UploadImageController::class, 'imageUploadPost'])->name('image.upload.store');

Enter fullscreen mode Exit fullscreen mode

GET FULL CODE: Laravel 8.0 Image Upload Example

Top comments (1)

Collapse
 
sloan profile image
Sloan the DEV Moderator

Hi there, we encourage authors to share their entire posts here on DEV, rather than mostly pointing to an external link. Doing so helps ensure that readers don’t have to jump around to too many different pages, and it helps focus the conversation right here in the comments section.

If you choose to do so, you also have the option to add a canonical URL directly to your post.