Install CKEditor on Laravel-admin
At first, install CKEditor on laravel-admin follow the steps below.
https://github.com/laravel-admin-extensions/ckeditor
Adding file upload function on CKEditor
config/admin.php
...
'ckeditor' => [
'enable' => true,
'config' => [
'filebrowserImageUploadUrl' => '/admin/fileupload', // Add here
]
]
...
Another options here.
app/Admin/routes.php
use Illuminate\Routing\Router;
Admin::routes();
Route::group([
'prefix' => config('admin.route.prefix'),
'namespace' => config('admin.route.namespace'),
'middleware' => config('admin.route.middleware'),
'as' => config('admin.route.prefix') . '.',
], function (Router $router) {
$router->get('/', 'HomeController@index')->name('home');
$router->post('/fileupload', 'FileuploadController@index'); // Add here
...
});
app/Http/Middleware/VerifyCsrfToken.php
<?php
namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
class VerifyCsrfToken extends Middleware
{
/**
* The URIs that should be excluded from CSRF verification.
*
* @var array
*/
protected $except = [
'/admin/fileupload', // Add here
];
}
app/Admin/Controllers/FileuploadController.php
<?php
namespace App\Admin\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class FileUploadController extends Controller
{
public function index(Request $request)
{
$image = $request->file('upload');
$name = substr(str_shuffle('1234567890abcdefghijklmnopqrstuvwxyz'), 0, 12);
$extension = $image->getClientOriginalExtension();
$newname = $name . '.' . $extension;
// you can change third variable as filesystem you want.
$image->storeAs([ANY_DIRECTORY_YOUWANT], $newname, 'public');
$url = [YOUR_PUBLIC_PATH] .$newname;
$param = [
'uploaded' => 1,
'fileName' => $newname,
'url' => $url
];
return response()->json($param, 200);
}
}