In this tutorial you will learn about the Laravel 8 Integrate Summernote Tutorial Example and its application with practical example.
In this Laravel 8 Integrate Summernote Tutorial Example Tutorial I’ll show you how to install and use Summernote editor in laravel 8. In this tutorial you will learn to install and use Summernote editor in laravel 8.
While creating forms we come to situation where we may text editor field so that we can insert and save html and other text into database. The summernote editor is feature rich wysiwyg html editor allows us to integrate text editor fields in html form. In this laravel 8 summernote editor integration example I will guide you through step by step to install and use summernote wysiwyg editor in laravel 8 application.
Laravel 8 Integrate Summernote Tutorial Example
In this step by step tutorial I will demonstrate you how to install and use summernote wysiwyg editor in laravel 8 application. Please follow the instruction given below:
- Step 1: Install Laravel 8 App
- Step 2: Connecting App to Database
- Step 3: Create Migration and Model File
- Step 4: Add Routes
- Step 5: Create Controller
- Step 6: Create Blade File
- Step 7: Run Development Server
- Step 8: Test App
Step 1: Install Laravel 8 App
First of all we need to create a fresh laravel project, download and install Laravel using the below command
1 |
composer create-project --prefer-dist laravel/laravel blog |
Step 2: Connecting App to Database
Now, lets create a MySQL database and connect it with laravel application. After creating database we need to set database credential in application’s .env file.
1 2 3 4 5 6 |
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_Password |
Step 3: Create Migration and Model File
Now, in this step we will create model and migration file for form. Please run the following command:
1 2 3 |
cd blog php artisan make:model Post -m |
Now, go to database/migrations and open create_posts_table.php. Then update the following code into create_posts_table.php file, as follow:
1 2 3 4 5 6 7 8 9 |
public function up() { Schema::create('posts', function (Blueprint $table) { $table->id(); $table->string('title'); $table->longText('description'); $table->timestamps(); }); } |
Now, run the migration to create database table using following artisan command:
1 |
php artisan migrate |
The above command will create tables in your database. Then open Post.php model file and put the following code into Post.php model file, which is placed on App/Models directory:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Post extends Model { use HasFactory; protected $fillable = ['title','description']; } |
Step 4: Add Routes
After this, we need to define routes in “routes/web.php” file. Lets open “routes/web.php” file and add the following routes in it.
routes/web.php
1 2 3 4 5 |
use App\Http\Controllers\PayController; Route::get('posts', [PostController::class, 'index']); Route::post('posts', [PostController::class, 'store']); Route::get('posts/{id}', [PostController::class, 'show']); |
Step 5: Create Controller
Now, lets create a controller named PostController using command given below –
1 |
php artisan make:controller PostController |
Now, go to app/http/controllers and open PostController.php file. And put the following code into your PostController.php file, as follow:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Models\Post; class PostController extends Controller { /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { return view('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(); Post::create($input); return redirect()->back(); } /** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show(Post $post) { return view('display',compact('post')); } } |
Step 6: Create Blade File
In this step we will create blade file. Now, go to resources/views folder. And create 2 blade views that named display.blade.php and create.blade.php the file inside this folder. Then open create.blade.php file and update the following code into create.blade.php file, as follow:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
<!DOCTYPE html> <html> <head> <title>How To Use Summernote Editor In Laravel 8</title> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/css/bootstrap.min.css"/> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.18/summernote.min.css"/> <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/js/bootstrap.min.js"></script> <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">Laravel Summernote Example Tutorial</h6> </div> <div class="card-body"> <form method="post" action="{{ url('posts') }}" 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> |
Now open display.blade.php file and update the following code into your list.blade.php file, as follow:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
<!DOCTYPE html> <html> <head> <title>Use Summernote Editor In Laravel</title> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/css/bootstrap.min.css"/> <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/js/bootstrap.min.js"></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">Use Summernote Editor In Laravel</h6> </div> <div class="card-body"> <table class="table table-bordered"> <tr> <th>No.</th> <th>Title</th> <th>Description</th> </tr> <tr> <td>{{ $post->id }}</td> <td>{{ $post->title }}</td> <td>{!! $post->description !!}</td> </tr> </table> </div> </div> </div> </div> </div> </body> </html> |
Step 7: Run Development Server
Now we are ready to run our example so lets start the development server using following artisan command –
1 |
php artisan serve |
Now, open the following URL in browser to see the output –
1 |
http://localhost:8000/posts |