How to Upload Image using Summernote Editor in Laravel

Laravel Summernote Image Upload Example; In this tutorial, you will understand how to upload image using summernote editor in laravel public storage folder. Summernote editor store the images along with summernote editor’s content in the database easily.

The summernote is a profound and powerful JavaScript package that helps you build WYSIWYG editors online. Let’s see the below example to upload images/files using summernote in laravel application.

How to Use Summernote Editor for Image Upload in Laravel

Step 1: Install Laravel App
Step 2: Connect Database to App
Step 3: Manage Model and Migration
Step 4: Create Controller
Step 5: Add Routes
Step 6: Create Blade Files
Step 7: Start Laravel App

Install Laravel App

First run the following command in terminal to install laravel fresh app for laravel summernote image upload funcationality.

composer create-project laravel/laravel laravel-app

Go inside the app

cd laravel-app

Connect App to Database

Open the .env file and add your database credentials such as database name, username equally important password:


Generate Model and Migration

Now generate model and migration file just adding the below command in your terminal which is generate a model file and migration which will show your database table after running the migration command.

php artisan make:model Post -m

Open app/Models/Post.php and add the values in the newly generated models file.


namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Post extends Model
    use HasFactory;
    protected $fillable = [
        'title', 'description', 'image'

Open database/migrations/create_posts_table.php and insert the table values inside the file.


use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreatePostsTable extends Migration
     * Run the migrations.
     * @return void
    public function up()
        Schema::create('posts', function (Blueprint $table) {

     * Reverse the migrations.
     * @return void
    public function down()

Next, open the terminal, type the recommended command and evoke the command to run the migration.

php artisan migrate

Create Controller

Now you need to create a controller just adding the below command and generate a new resource controller PostController.

php artisan make:controller PostController

Next, in this file we write image upload code, image will upload on “uploads” folder in public directory. So, open app/Http/Controllers/PostController.php file and update the below code on it;


namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Post;

class PostController extends Controller
    public function index()

        return view('posts');

    public function store(Request $request)
        $request->validate($request, [
             'title' => 'required',
             'description' => 'required'

       $content = $request->input('description');
       $dom = new \DomDocument();
       $dom->loadHtml($content, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
       $imageFile = $dom->getElementsByTagName('img');

       foreach($imageFile as $item => $image){
           $data = $image->getAttribute('src');
           list($type, $data) = explode(';', $data);
           list(, $data)      = explode(',', $data);
           $imgeData = base64_decode($data);
           $image_name= "/uploads/" . time().$item.'.png';
           $path = public_path() . $image_name;
           file_put_contents($path, $imgeData);

           $image->setAttribute('src', $image_name);

       $content = $dom->saveHTML();
       $post = Post::create([
            'title' => $request->title,
            'body' => $content


Create Routes

In laravel 9 route section have some change here you need to use your controller then initialize the controller class. Open your “routes/web.php” file and your routes same as below.


use Illuminate\Support\Facades\Route;
use App\Http\Controllers\PostController;

Route::get('posts', [PostController::class, 'index'])->name('posts.index');
Route::post('posts', [PostController::class, 'store'])->name('');

Create Blade File

Now create a new blade file named as resources\views\posts.blade.php and update the below code on it.


<!DOCTYPE html>

<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>How to Upload Image using Summernote Editor</title>
<link href="" rel="stylesheet">
<link rel="stylesheet" href="" />

    <div class="container mt-4">
        <h3 class="text-center">How to Upload Image using Summernote Editor in Laravel</h3>
        <form method="post" action="{{ route('') }}" enctype="multipart/form-data" class="mt-5">
            <div class="form-group">
                <input type="text" name="title" class="form-control" />
            <div class="form-group my-3">
                <textarea id="summernote" name="description"></textarea>
            <div class="form-group text-center">
                <button type="submit" class="btn btn-success btn-block">Publish</button>

    <script src=""></script>
    <script src=""></script>
    <script src=""></script>

    <script type="text/javascript">
        $(document).ready(function () {
                height: 300,


Start Laravel App

php artisan serve

Type the suggested url on the browser’s address bar to see the app in the action.

I hope you enjoy with this example…

Leave a Comment