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=
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');
GET FULL CODE: Laravel 8.0 Image Upload Example
Top comments (1)
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.