By Hardik Savani March 16, 2022 Category : LaravelPauseUnmuteLoaded: 4.19%FullscreenThis simple article demonstrates of laravel tinymce editor example. if you have a question about laravel tinymce image upload then I will give a simple example with a solution. I would like to show you how to use tinymce editor in laravel. I would like to show you how to install tinymce in laravel. follow below step for TinyMCE editor in laravel.
you can use TinyMCE rich text box editor with laravel 6, laravel 7, laravel 8 and laravel 9 versions as well.
In this tutorial, we will create a posts table with a title and body column. we will create for with input for the title and TinyMCE rich textbox for the body, Then save it to the database.
Step 1: Install Laravel
This is optional; however, if you have not created the laravel app, then you may go ahead and execute the below command:
<?php 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('posts', function (Blueprint $table) { $table->id(); $table->string('title'); $table->text('body'); $table->timestamps(); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::dropIfExists('posts'); }};
now let's run migration command:
php artisan migrate
now, just create post model and add code as like bellow:
app/Models/Post.php
<?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory;use Illuminate\Database\Eloquent\Model; class Post extends Model{ use HasFactory; protected $fillable = [ 'title', 'body', ];}
In this is step we need to create some routes for listing posts and creating post.
routes/web.php
<?php use Illuminate\Support\Facades\Route; use App\Http\Controllers\PostController; /*|--------------------------------------------------------------------------| 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('posts/create',[PostController::class,'create']);Route::post('posts/store',[PostController::class,'store'])->name('posts.store');
Step 4: Create Controller
in this step, we need to create PostController and add following code on that file:
app/Http/Controllers/PostController.php
<?php namespace App\Http\Controllers; use Illuminate\Http\Request;use App\Models\Post; class PostController extends Controller{ /** * Write code on Method * * @return response() */ public function create() { return view('postsCreate'); } /** * Write code on Method * * @return response() */ public function store(Request $request) { $this->validate($request, [ 'title' => 'required', 'body' => 'required' ]); $post = Post::create([ 'title' => $request->title, 'body' => $request->body ]); dd($post->toArray()); }}
Step 5: Create Blade Files
here, we need to create blade files for index and create. so let's create one by one files: