Laravel 9 Image Upload with Tailwind css Example




Laravel 9 Image Upload with Tailwind css Example

Hi friends,

Here, I will show you how to works laravel 9 image upload with tailwind css . I explained simply about how to uploading an image with tailwind css in laravel 9. you can understand a concept of laravel 9 image upload with tailwind css example. you can see laravel 9 image upload with tailwind css image. So, let's follow few step to create example of laravel 9 image upload with tailwind css laravel.

And as well as, how to validate image mime type, size, dimension, etc on laravel controller by using laravel validation rules.

This Image upload in the tutorial will create an image upload with tailwind css in laravel 9, which is used to store images in the database and storage directory.

This tutorial will work with Laravel versions 5, 6, 7, and 8. When syntax is different across versions, the different syntax will be demonstrated.

Let's start following example:

Step 1: Download Laravel

Let us begin the tutorial by installing a new laravel application. if you have already created the project, then skip following step.

composer create-project laravel/laravel example-app

Step 2 : Setup Databases

Now, update your in env file.








Step 3 : Create Model ,Migration ,Controller

Now in this step run shorthand command to create image modal, migration and controller.

php artisan make:model Image -mc



use Illuminate\Database\Migrations\Migration;

use Illuminate\Database\Schema\Blueprint;

use Illuminate\Support\Facades\Schema;

return new class extends Migration



* Run the migrations.


* @return void


public function up()


Schema::create('images', function (Blueprint $table) {







* Reverse the migrations.


* @return void


public function down()


Schema::table('images', function (Blueprint $table) {





Step 4 : Add Model

Ok, so after run the command you will find "app/Models/Image.php" and put bellow content in Image.php file:



namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;

use Illuminate\Database\Eloquent\Model;

class Image extends Model


use HasFactory;

protected $fillable = [




Step 5 : Add Controller

In this step, we will create a new ImageController; in this file, we will add two method index() and store() for render view and store image logic.

Let's create ImageController by following command:



namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Models\Image;

class ImageController extends Controller



* Write code on Method


* @return response()


public function index()


return view('image');



* Write code on Method


* @return response()


public function store(Request $request)


$this->validate($request, [

'image' => 'required|image|mimes:jpg,png,jpeg,gif,svg|max:2048',


$image_path = $request->file('image')->store('image', 'public');

$data = Image::create([

'image' => $image_path,


session()->flash('success', 'Image Upload successfully');

return redirect()->route('image.index');



Step 6 : Add Routes



use Illuminate\Support\Facades\Route;

use App\Http\Controllers\ImageController;



| Web Routes



| Here is where you can register web routes for your application. These

| routes are loaded by the RouteServiceProvider within a group which

| contains the "web" middleware group. Now create something great!



Route::get('/image', [ImageController::class,'index'])->name('image.index');

Route::post('/image', [ImageController::class,'store'])->name('');

Step 7: Add Blade File


<!DOCTYPE html>

<html lang="en">


<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<meta http-equiv="X-UA-Compatible" content="ie=edge">

<title>Laravel 9 Image Upload with Tailwind css Example</title>

<script src=""></script>



<div class="relative flex items-center min-h-screen justify-center overflow-hidden">

<form action="{{ route('') }}" method="POST" class="shadow p-12" enctype="multipart/form-data">


<label class="block mb-4">

<span class="sr-only">Choose File</span>

<input type="file" name="image"

class="block w-full text-sm text-gray-500 file:mr-4 file:py-2 file:px-4 file:rounded-full file:border-0 file:text-sm file:font-semibold file:bg-blue-50 file:text-blue-700 hover:file:bg-blue-100" />


<span class="text-red-600 text-sm">{{ $message }}</span>



<button type="submit" class="px-4 py-2 bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded-full">Submit</button>





Step 8: Migrate database & Storage links

php artisan migrate

Storage links to public directory.

php artisan storage:link

Run Laravel App:

All steps have been done, now you have to type the given command and hit enter to run the laravel app:

php artisan serve

Now, you have to open web browser, type the given URL and view the app output:



I hope it can help you...

#Laravel 9