create.blade.php
<div class="row mb-3">
<div class="col-md-12 mb-3">
<label for="body">Body</label>
<textarea name="body" id="body" class="form-control"></textarea>
</div>
</div>
<script src="{{ asset('themes/ckeditor/ckeditor.js') }}"></script>
<script>
CKEDITOR.replace('body' ,{
filebrowserUploadUrl : '/admin/upload/image',
filebrowserImageUploadUrl : '/admin/upload/image'
});
</script>
web.php
Route::post('/admin/upload/image', 'AdminController@upload');
AdminController.php
public function upload()
{
$year = Carbon::now()->year;
$imagePath = "/admin/upload/image/{$year}/";
$file = request()->file('upload');
$filename = $file->getClientOriginalName();
if (file_exists(public_path($imagePath).$filename)) {
$filename = Carbon::now()->timestamp.$filename;
}
$file->move(public_path($imagePath), $filename);
$url = $imagePath.$filename;
return "<script>window.parent.CKEDITOR.tools.callFunction(1, '{$url}', '')</script>";
}
VerifyCsrfToken.php
protected $except = [
'admin/upload/image'
];
When I upload an image in CKEditor I get this error.
The requested resource /admin/upload/image?CKEditor=body&CKEditorFuncNum=1&langCode=fa was not found on this server.