Image Upload in Summernote Editor Using Laravel

Websolutionstuff | Jul-09-2021 | Categories : Laravel PHP

In this post we will see how to upload image in summernote editor. there are many editor available in laravel to save rich text here we will use summernote editor.

summernote editor is a simple but customizable, powerful rich text editor for the web, here you can image upload in summernote editor using laravel, so let's see how to implement summernote editor with image upload example.

Here, i have ceated one controller to upload image in summernote editor.

php artisan make:controller ImageUploadController

Now, copy below code in this location app/Http/Controllers/ImageUploadControler.php



namespace App\Http\Controllers;

use Illuminate\Http\Request;

class ImageUploadController extends Controller
    public function image()
        return view('summernote');

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

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

        foreach($images as $k => $img){
            $data = $img->getAttribute('src');

            list($type, $data) = explode(';', $data);
            list(, $data)      = explode(',', $data);
            $data = base64_decode($data);

            $image_name= "/upload/" . time().$k.'.png';
            $path = public_path() . $image_name;

            file_put_contents($path, $data);
            $img->setAttribute('src', $image_name);

        $description = $dom->saveHTML();



Now, create blade file for view.

<!DOCTYPE html>
    <title>Image Upload in Summernote Editor Using Laravel -</title>
    <script type="text/javascript" src=""></script> 
    <link rel="stylesheet" 
    href="" />

    <script type="text/javascript" src=""></script>
    <link href="" rel="stylesheet">
    <script src=""></script>
    <div class="row" style="margin-top: 50px;">
        <div class="col-md-8 col-md-offset-2">
            <div class="panel panel-primary">
                <div class="panel-heading">
                    <h4>Image Upload in Summernote Editor Using</h4>
                <div class="panel-body">
                    <form method="POST" action="{{ route('image.upload') }}">
                        {{ csrf_field() }}
                        <div class="form-group">
                            <textarea class="form-control summernote" name="description"> 
                        <button type="submit" class="btn btn-success">Submit</button>
    <script type="text/javascript">
        $(document).ready(function() {
               height: 200,


Recommended Post
Featured Post
How To Create Dynamic Bar Chart In Laravel
How To Create Dynamic Bar Char...

In this article, we will show you how to create a dynamic bar chart in laravel. charts are used to represent data i...

Read More


How To Get Last Record In Laravel 8
How To Get Last Record In Lara...

In this example, we will see how to get the last record in laravel 8. You can simply get the last record using laravel 8...

Read More


How To Integrate Mailchimp API In Laravel 9
How To Integrate Mailchimp API...

In this article, we will see how to integrate mailchimp API in laravel 9. Here we will learn how we can integr...

Read More


How To Check Occupied Disk Space In Laravel
How To Check Occupied Disk Spa...

Many times we need requirements to check the occupied disk space of the server on the admin side and we are checking man...

Read More