Home >Backend Development >PHP Tutorial >How to Image Upload with CKeditor in Laravel Tutorial

How to Image Upload with CKeditor in Laravel Tutorial

Barbara Streisand
Barbara StreisandOriginal
2025-01-12 08:25:46262browse

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.

Example of using CKEditor to upload images in Laravel 11

Step 1: Install Laravel 11

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>

Step 2: Create a route

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>

Step 3: Create Controller

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn