shahr's avatar
Level 10

The POST method is not supported for this route. Supported methods: GET, HEAD.

When I upload an image with ckeditor. I get this error.

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>";
}
0 likes
3 replies
Sinnbeck's avatar

Change this route to post

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

Please or to participate in this conversation.