Laravel Summernote Editor Example Tutorial
Jun 23, 2021 . Admin
Hi Guys,
Today,In this tutorial I will show you how to integrate summernote editor in laravel application. Summernote editor utilized in our laravel application.
Summernote uses the Open Source libraries jQuery and Bootstrap, if you are using the Boostrap 3 or 4 versions of Summernote, or just jQuery if you use the Lite version of Summernote. Summernote can be used with or without a form.
Here,i will give you a simple and easy example how to use Summernote in laravel simply follow my all steps.
Step 1 : Install Laravel AppIn this step, You can install laravel fresh app. So open terminal and put the bellow command.
composer create-project --prefer-dist laravel/laravel blogStep 2 : Setup Database Configuration
After successfully install laravel app next we configure databse setup. We will open ".env" file and change the database name, username and password in the env file.
DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=Enter_Your_Database_Name DB_USERNAME=Enter_Your_Database_Username DB_PASSWORD=Enter_Your_Database_PasswordStep 3 : Create Table Migration and Model
In this step we have to create migration for blogs table and book Model using Laravel php artisan command, so first fire bellow command:
php artisan make:model Blog -m
After this command you have to put bellow code in your migration file for create bookd table.
Path : /database/migrations/2021_06_22_124618_create_blogs_table.php<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; class CreateBlogsTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create('blogs', function (Blueprint $table) { $table->id(); $table->string('title'); $table->text('description'); $table->timestamps(); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::dropIfExists('blogs'); } }
Now we need to run migration be bellow command:
php artisan migrate
After you have to put bellow code in your Blog model file for create blogs table.
Path : app/Models/Blog.php<?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Blog extends Model { use HasFactory; protected $fillable = [ 'title', 'description', ]; }Step 3 : Create Route
now, we require to create route for Blogcontroller in laravel application. so open your "routes/web.php" file and add following route.
Path : app/Models/Blog.php<?php use Illuminate\Support\Facades\Route; use App\Http\Controllers\BlogController; /* |-------------------------------------------------------------------------- | 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::resource('blogs', BlogController::class);Step 4 : Create Controler
Here this fourth step now we should create new controller as BlogController. So run bellow command and create new controller.
php artisan make:controller BlogControllerAfter successfully run above command . So, let's copy bellow code and put on BlogController.php file. Path : app/http/controller/BlogController.php
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Models\Blog; class BlogController extends Controller { /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { return view('blog.create'); } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $input = $request->all(); Blog::create($input); return redirect()->back(); } /** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show(Blog $blog) { return view('blog.show',compact('blog')); } }Step 5 : Create Blade File
In last step. In this step we have to engender two blade file. So mainly we have to create blog folder in view directory. First file is create and second one is show file. So finally you have to create following file and put bellow code:
Path : /resources/views/blog/create.blade.php<!DOCTYPE html> <html> <head> <title>How To Use Summernote Editor In Laravel? - MyWebTuts.com</title> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha256-aAr2Zpq8MZ+YA/D6JtRD3xtrwpEz2IqOS+pWD/7XKIw=" crossorigin="anonymous" /> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.18/summernote.min.css" integrity="sha256-n3YISYddrZmGqrUgvpa3xzwZwcvvyaZco0PdOyUKA18=" crossorigin="anonymous" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha256-OFRAJNoaD8L3Br5lglV7VyLRf0itmoBzWUoM+Sji4/8=" crossorigin="anonymous"></script> <!-- include libraries(jQuery, bootstrap) --> <link href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet"> <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script> </head> <body> <div class="container"> <div class="row"> <div class="col-md-8 offset-2 mt-5"> <div class="card"> <div class="card-header bg-info"> <h6 class="text-white">How To Use Summernote Editor In Laravel? - NiceSnippets.com</h6> </div> <div class="card-body"> <form method="post" action="{{ route('blogs.store') }}" enctype="multipart/form-data"> @csrf <div class="form-group"> <label>Title</label> <input type="text" name="title" class="form-control"/> </div> <div class="form-group"> <label><strong>Description :</strong></label> <textarea class="summernote" name="description"></textarea> </div> <div class="form-group text-center"> <button type="submit" class="btn btn-success btn-sm">Save</button> </div> </form> </div> </div> </div> </div> </div> <script type="text/javascript"> $(document).ready(function() { $('.summernote').summernote(); }); </script> </body> </html>/resources/views/blog/show.blade.php
<!DOCTYPE html> <html> <head> <title>How To Use Summernote Editor In Laravel? - MyWebTuts.com</title> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha256-aAr2Zpq8MZ+YA/D6JtRD3xtrwpEz2IqOS+pWD/7XKIw=" crossorigin="anonymous" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha256-OFRAJNoaD8L3Br5lglV7VyLRf0itmoBzWUoM+Sji4/8=" crossorigin="anonymous"></script> </head> <body> <div class="container"> <div class="row"> <div class="col-md-12"> <div id="showimages"></div> </div> <div class="col-md-6 offset-3 mt-5"> <div class="card"> <div class="card-header bg-info"> <h6 class="text-white">How To Use Summernote Editor In Laravel? - MyWebTuts.com</h6> </div> <div class="card-body"> <table class="table table-bordered"> <tr> <th>No.</th> <th>Title</th> <th>Description</th> </tr> <tr> <td>{{ $blog->id }}</td> <td>{{ $blog->title }}</td> <td>{!! $blog->description !!}</td> </tr> </table> </div> </div> </div> </div> </div> </body> </html>
Now we are ready to run our example so run bellow command for quick run:
php artisan serveNow you can open bellow URL on your browser:
http://localhost:8000/blogs
It will help you...