该路由不支持POST方法。支持的方法:GET,HEAD。 ckeditor

时间:2020-07-30 12:32:52

标签: ckeditor laravel-5.8

当我使用ckeditor上传图像时。我收到此错误。

ckeditor

edit.blade.php

CKEDITOR.replace('body', {
    filebrowserUploadUrl: "{{route('upload', ['_token' => csrf_token() ])}}",
    filebrowserUploadMethod: 'form',
    extraPlugins: 'easyimage',
    cloudServices_tokenUrl: 'http://localhost:8000/admin/ckeditor/image-upload',
    cloudServices_uploadUrl: 'http://localhost:8000/admin/ckeditor/image-upload'
});

web.php

Route::namespace('Admin')->prefix('admin')->group(function (){
    Route::get('dashboard', 'DashboardController@dashboard')->name('dashboard.index');
    Route::get('ckeditor/image-upload', 'DashboardController@upload')->name('upload');

DashboardController.php

public function upload(Request $request)
{
    $this->validate(request() , [
        'upload' => 'required|mimes:jpeg,png,bmp',
    ]);

    $year = Carbon::now()->year;
    $imagePath = "public/upload/images/{$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>";
}

当我在web.php中更改

我再次看到此错误

Route::post('ckeditor/image-upload', 'DashboardController@upload')->name('upload');

ckeditor

0 个答案:

没有答案