ojwando's avatar

The GET method is not supported for this route. Supported methods: PUT.

The GET method is not supported for this route. Supported methods: PUT.

I am using classic ckeditor for my textarea field. i have configured the editor to upload an embedded image which it does. the problem is that when i submit the form i get the above error. Here is my route:

Route::put('posts/{post}/update',[PostController::class,'update'])->name('posts.update');

Here is the form:

@extends('posts.mastershow')

@section('title','Edit Post') @section('content')

update

   @section('script')

ClassicEditor .create(document.querySelector('#body'), { ckfinder: { uploadUrl: "{{ route('ckeditor.upload', ['_token' => csrf_token()]) }}",

    }
})
.catch(error => {
    console.error(error);
});

@endsection

` Here is the controller:

`
public function update(Request $request, Post $post){

        if($request->hasFile('image')) {
        // Get filename with extension           
         $filenameWithExt = $request->file('image')->getClientOriginalName();
        // Get just filename
        $filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);            
       // Get just ext
        $extension = $request->file('image')->getClientOriginalExtension();
        //Filename to store
        $fileNameToStore = $filename.'_'.time().'.'.$extension;                       
      // Upload Image
        $path = $request->file('image')->storeAs('public/images', $fileNameToStore);
    } else {
        $fileNameToStore = 'noimage.jpg';
    }
   $post->image = $fileNameToStore;
  $post->update([

    'title'=>$request->title,
     'tag'=>$request->tag,
    'body'=>$request->body,
    'slug'          => $request->slug,
    'image'=> $fileNameToStore,
  ]);

  $post->save();
  return redirect('/');
    




}

`

0 likes
10 replies
tykus's avatar

Can you please format your code snippets properly so that your post is actually readable?

Also, what URL are you visiting that gives you that error message?

1 like
ojwando's avatar

@tykus Here is the form

<form action ="{{ route('posts.update',$post->slug) }}"  method = "POST"  enctype="multipart/form-data" >
     @csrf
     @method('PUT')
<div class="form-group">
    <label for="name">Post Title</label>
    <input class="form-control" name="title" placeholder="Title" value= "{{$post->title}}"">
</div>
    <div class="form-group">
        <label for="slug">Slug</label>
        <input type="text" name="slug" class="form-control" value="{{ $post->slug }}" placeholder="post-slug">
    </div>
    <div class="form-group">
        <label for="slug">Tag</label>
        <input type="text" name="tag" class="form-control" value="{{ $post->tag }}" placeholder="post-tag">
    </div>

<div class="form-group">
    <label for="name">Subject</label>
    <textarea   name="body" id="body" cols="30" rows="10"   class="form-control" >{{ old('body', $post->body) }}</textarea>
</div>

<div class="form-group">
    <label for="name">Image</label>
    <input type="file" class="form-control" name="image" placeholder="body" value="{{$post->image}}""  >
</div>

<button type="submit" class="btn btn-success">update</button> 
</form>
1 like
tykus's avatar

@ojwando when do you see the error message; before or after submitting the form?

1 like
ojwando's avatar

Without the embedded image updates happens with no problem

1 like
Snapey's avatar

Is your route model binding setup to accept slug?

1 like
Ben Taylor's avatar

You form element has a space where you set the method. Not sure if this ignores setting it to post and defaults to get? Try removing the spaces

method = "POST"

1 like
Snapey's avatar

run artisan route:list and check the format and order of the posts route

Please or to participate in this conversation.