Laravel 9 Image Upload with Tailwind CSS Tutorial

Reading Time: 7 minutes
1,656 Views

Inside this article we will see the concept i.e Laravel 9 Image Upload with Tailwind CSS Tutorial. Article contains the classified information about Image upload in laravel with the layout build in tailwind css.

Tailwind CSS is basically a utility-first CSS framework for rapidly building custom user interfaces. It is a highly customizable, low-level CSS framework that gives you all of the building blocks you need to build bespoke designs without any annoying opinionated styles you have to fight to override.

Learn More –

Let’s get started.

Laravel Installation

Open terminal and run this command to create a laravel project.

composer create-project laravel/laravel myblog

It will create a project folder with name myblog inside your local system.

To start the development server of laravel –

php artisan serve

URL: http://127.0.0.1:8000

Assuming laravel already installed inside your system.

Create Database & Connect

To create a database, either we can create via Manual tool of PhpMyadmin or by means of a mysql command.

CREATE DATABASE laravel_app;

To connect database with application, Open .env file from application root. Search for DB_ and update your details.

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

Create Migration & Model

Open project into terminal and run this command. This command will create model file as well as migration file.

$ php artisan make:model Image -mc

It will create two files:

  • Image.php, a model file inside /app/Http/Models folder.
  • 2022_08_11_153105_create_images_table.php, a migration file inside /database/migrations folder.

Open migration file xxx_create_images_table.php and write this code into it.

xxx_create_images_table.php

Open model file Image.php and write this following code into it.

Image.php

Run Migration

Open project into terminal and run this command:

$ php artisan migrate

It will create images table inside your database.

Create Controller

Next,

We need to create a controller file. Again, back to project terminal and run this command.

$ php artisan make:controller UploadImageController

It will create UploadImageController.php file inside /app/Http/Controllers folder.

Open UploadImageController.php and write this following code into it.

UploadImageController.php

Create Blade Layout File

Go to /resources/views folder and create a file with name image.blade.php

Open image.blade.php and write this complete code into it.

image.blade.php

Create Image Storage Path

We will generate a storage path to save upload images into application.

Run this command to create storage path:

$ php artisan storage:link

It will create /storage/app/public folder into root of the application. Images will be upload and saved into image folder inside it.

Add Route

Open web.php from /routes folder and add these route into it.

web.php

Application Testing

Run this command into project terminal to start development server,

php artisan serve

URL: http://127.0.0.1:8000/image-upload

Once you select an image and upload. It will save uploaded image into storage folder and save into database table.

Database table view of images table:

We hope this article helped you to Learn Laravel 9 Image Upload with Tailwind CSS Tutorial in a very detailed way.

If you liked this article, then please subscribe to our YouTube Channel for PHP & it’s framework, WordPress, Node Js video tutorials. You can also find us on Twitter and Facebook.