Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Hibt's avatar
Level 1

MethodNotAllowedHttpException in RouteCollection.php line 207: Error

Any one here can help me . i m facing some problem

MethodNotAllowedHttpException in RouteCollection.php line 207:

this error is displayed. i am developing a image gallery app. when i try to update image then, this error displayed.

help me plz........???????

0 likes
28 replies
Hibt's avatar
Level 1

My routing path is this...


Route::get('image','filesController@indeximage');

Route::get('image/create','filesController@createimage');

Route::post('image','filesController@storeimage');

Route::put('image/{id}/edit','filesController@editimage');

Route::patch('image/{id}','filesController@updateimage');

plz.... i am waiting for your response ???????????

bestmomo's avatar

What's the url request when you get this error ?

Hibt's avatar
Level 1

Dear @SetKyarWaLar ... Editing form is Here ...

{!! Form::model($imagee,['url' =>'/image/'.$imagee->id ,'method' => 'PUT', 'files'=>true]) !!}

<div class="form-group">
       {!! Form::label('userfile','Upload Image:') !!}
       {!! Form::file('userfile',null,['class'=>'form-control']) !!}
 </div><!--End of form-group -->
  
  {!! Form::submit("update",['class'=>'btn btn-primary']) !!}

{!! Form::close() !!}
Hibt's avatar
Level 1

@prithvi dear filesController is here ..

<?php 
namespace App\Http\Controllers;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\fileddata;
use Illuminate\Http\Request;
use Input;
use validator;
use App\Http\Requests\Filesrequest;

class filesController extends Controller {

   

    public function indeximage() {

     $imgg = fileddata::get()->all();                
 
        return view('pages.show_page',compact('imgg'));

    }

    public function createimage() {
   
       
       return view('pages.create_page');    
       }

    public function storeimage(Filesrequest $request) {
 
     
   
      $imaged= new fileddata;

      if($request->hasFile('userfile')) {

       $file= $request->file('userfile');

      $destination_path='uploads/';
   
      $Orname = $file->getClientOriginalName();

      $filename= str_random(6).'_'.$Orname;
     
      $file->move($destination_path,$filename);
 
     $imaged->file = $destination_path.$filename;

     $imaged->save();     
        }
 
     else {
   
      echo "File not uploaded";

     }


     return redirect('image');
 
      }      

    
    public function showimage($id) {


       }

      

    public function editimage($id,Filesrequest $request){

      $imagee= fileddata::findOrFail($id);

      return view('pages.edit_page')->with('imagee',$imagee);
    }

   
   public function updateimage($id,Filesrequest $request)
   
   {
    
    $imagedd =fileddata::findOrFail($id);

    
   if ($request->hasFile('userfile')) {

       $file= $request->file('userfile');

      $destination_path='uploads/';
   
      $Orname = $file->getClientOriginalName();

      $filename= str_random(6).'_'.$Orname;
     
      $file->move($destination_path,$filename);
 
     $imagedd->file = $destination_path.$filename;

     $imagedd->save();     
        }
 
     else {
   
      echo "File not updated";

     }


     return redirect('image');

     }

   
   public function destroyimage($id) {


   }

     

}




Hibt's avatar
Level 1

@bestmomo Using PUT method for Request ..!!!

routes and Controller is given above..

bestmomo's avatar

I think you need this route to get your form :

Route::get('image/{id}/edit','filesController@editimage');
Hibt's avatar
Level 1

@bestmomo i am write route like your instructions .... but when i write the url for editing .... Controller not move to edit form

bestmomo's avatar

@Hibt

If you write route as this you should go to editimage of your controller. Could you show the result of php artisan route:list ?

Snapey's avatar

IGNORE THIS

Change form model to include /edit

from

{!! Form::model($imagee,['url' =>'/image/'.$imagee->id ,'method' => 'PUT', 'files'=>true]) !!}

to

{!! Form::model($imagee,['url' =>'/image/'.$imagee->id.'/edit' ,'method' => 'PUT', 'files'=>true]) !!}
Hibt's avatar
Level 1
@bestmomo  ... Here is the route:list for files controller

  | auth       |
|        | GET|HEAD                       | image
                  |      | App\Http\Controllers\filesController@indeximage
      |            |
|        | GET|HEAD                       | image/create
                  |      | App\Http\Controllers\filesController@createimage
      |            |
|        | POST                           | image
                  |      | App\Http\Controllers\filesController@storeimage
      |            |
|        | GET|HEAD                       | image/{id}/edit
                  |      | App\Http\Controllers\filesController@editimage
      |            |
|        | PATCH                          | image/{id}
                  |      | App\Http\Controllers\filesController@updateimage






kingpabel's avatar

Look you are doing put request from form,but get data using patch in route,so change it like this


Route::put('image/{id}','filesController@updateimage');
{!! Form::model($imagee,['url' =>'/image/'.$imagee->id ,'method' => 'PUT', 'files'=>true]) !!}

bestmomo's avatar

@Snapey @thomaskim why adding 'edit' in url in form ?

@Hibt you say you dont get the form ? Could you debug to see if you go inside editimage method of your controller and what do you get ? Nothing ? Error ?

Snapey's avatar

yes sorry,just woke up... ;-o

send form to client with get to /image/{id}/edit which should go to controller@edit

receive update from client with put or patch to /image/{id} which should go to controller@update

Hibt's avatar
Level 1

i am not accessing the editing form ..... i d,nt why dear @Snapey @bestmomo @thomaskim And @prithvi ......

i am again showing routes file... i am also add '/edit' in model form


Route::get('sdsd', 'WelcomeController@index');

Route::get('home', 'HomeController@index');

Route::get('image','filesController@indeximage');

Route::get('image/create','filesController@createimage');

Route::post('image','filesController@storeimage');

Route::get('image/{id}/edit','filesController@editimage');

Route::put('image/{id}','filesController@updateimage');


prithvi's avatar

@Hibt : if you have done the route changes, don't add '/edit' to model form.

Snapey's avatar

so if you type hostname/image/1/edit in your browser, what happens?

Hibt's avatar
Level 1

@Snapey

i write that hostname/image/1/edit

but when i reload or refresh
it goes to

hostname/image

Snapey's avatar

but when i reload or refresh

just enter that url and press enter, not reload or refresh

Also, assuming that you have an image 1 in your model. If not, substitute for an image number that you do have

prithvi's avatar

@Hibt You don't need to pass Filesrequest $request to editimage function in your filesController

prithvi's avatar
prithvi
Best Answer
Level 6

@Hibt You are validating it in the updateimage function. You don't need it in the editimage function

Please or to participate in this conversation.