Home >Backend Development >PHP Tutorial >How to Image Upload with CKeditor in Laravel Tutorial
This tutorial demonstrates how to use CKEditor to implement the image upload function in Laravel 11.
CKEditor is a web-based open source WYSIWYG (WYSIWYG) editor that allows users to edit text content in the browser. It is a powerful tool that enables users to create and format text, add images and multimedia, and edit HTML code without any coding knowledge. First released in 2003, CKEditor has become a popular choice among web developers and content creators due to its versatility and ease of use. It is written in JavaScript and can be easily integrated into any web application.
In this example, we will create a simple CKEditor instance with an image upload option that saves the image to local storage. We will set up two routes, one for GET requests and one for POST requests (for image uploads). Once the user selects an image and submits it, the image will be stored in the "media" folder. You can also study Laravel 11 CORS middleware configuration examples.
First, we need to get a new Laravel 11 version application using the following command since we are starting from scratch. So, open your terminal or command prompt and run the following command:
<code class="language-bash">composer create-project laravel/laravel example-app</code>
In this step, we will add three routes with GET and POST methods in the routes/web.php
file. Let's add it.
routes/web.php
<code class="language-php"><?php use Illuminate\Support\Facades\Route; use App\Http\Controllers\CkeditorController; Route::get('ckeditor', [CkeditorController::class, 'index']); Route::post('ckeditor/upload', [CkeditorController::class, 'upload'])->name('ckeditor.upload'); ?></code>
In this step we have to create a new controller named CkeditorController
which contains index()
and update()
methods.
Please make sure you have created the public
folder within your media
directory as the images will be stored in that folder. Learn more...
The above is the detailed content of How to Image Upload with CKeditor in Laravel Tutorial. For more information, please follow other related articles on the PHP Chinese website!