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

Saikishore's avatar

Laravel Routing Issue for Post methods

Hi, I am trying to call controller using Routes. Everything is working fine when using GET method. When I worked on Post, i am not able to call the controller. Please check the below.

Error Code: Routing is not working

 Route::post('/accountSignUp', [
'as' => 'accountSignUp',
'uses' => 'UsersController@accountSignUp'
 ]);

can anybody suggest how to do it.

0 likes
21 replies
az_iar's avatar

change the route name to something else like

'as' => 'accountSignUp.post'
bart's avatar

You are using the same alias and method for both, get and post?! You should fix this.

Saikishore's avatar

@bart, I am using only one. That is for just explaining my issue. When I am using Get method, the url is working good. Coming to Post Url is not working.

milon's avatar

change the method name of post, this will work.

bart's avatar

Would you tell us how you send your post request?

RemiC's avatar

How your controller looks like ?

Can you send other Post request within your application ?

Saikishore's avatar

@RemiC,

Please check my Controller..UsersController

 public function accountSignUp()
{ 
   echo  $email = Input::get('email');
   echo  $firstname = Input::get('firstname');
   echo $lastname = Input::get('lastname');
}

Routes...

Route::post('/accountSignUp','UsersController@accountSignUp');

Please check and let me the solution.. Thanks..

RemiC's avatar

Everything seems correct. I replicated the exact same Routes / Controller function, works fine with postman...

Have you got a more detailed error log ? I suspect a http issue with your host. Which environment do you use ?

Saikishore's avatar

Getting the below error.. Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException

/var/www/project/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php#210

*/
protected function methodNotAllowed(array $others)
{

 throw new MethodNotAllowedHttpException($others);
}


/**
RemiC's avatar

Do you have both the Route::get('/accountSignUp) and Route:post(''/accountSignUp") in your routes.php file?

bashy's avatar

You have the exact same method, URI and named route?

P.s don't be using CamelCase in URIs, it's 2014 :)

2 likes
Saikishore's avatar

@RemiC, I am not using get and post for same method. i am using POST method only. This is my complete error message which is saved in Log.

           [2014-11-07 13:30:46] dev.ERROR: exception                                'Symfony\Component\HttpKernel\Exception\NotFoundHttpException' in /var/www/project_name/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php:148

Stack trace: #0 /var/www/project_name/vendor/laravel/framework/src/Illuminate/Routing/Router.php(1049): Illuminate\Routing\RouteCollection->match(Object(Illuminate\Http\Request)) #1 /var/www/project_name/vendor/laravel/framework/src/Illuminate/Routing/Router.php(1017): Illuminate\Routing\Router->findRoute(Object(Illuminate\Http\Request)) #2 /var/www/project_name/vendor/laravel/framework/src/Illuminate/Routing/Router.php(996): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request)) #3 /var/www/project_name/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(775): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request)) #4 /var/www/project_name/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(745): Illuminate\Foundation\Application->dispatch(Object(Illuminate\Http\Request)) #5 /var/www/project_name/vendor/barryvdh/laravel-debugbar/src/Middleware/Stack.php(34): Illuminate\Foundation\Application->handle(Object(Illuminate\Http\Request), 1, true) #6 /var/www/project_name/vendor/laravel/framework/src/Illuminate/Session/Middleware.php(72): Barryvdh\Debugbar\Middleware\Stack->handle(Object(Illuminate\Http\Request), 1, true) #7 /var/www/project_name/vendor/laravel/framework/src/Illuminate/Cookie/Queue.php(47): Illuminate\Session\Middleware->handle(Object(Illuminate\Http\Request), 1, true) #8 /var/www/project_name/vendor/laravel/framework/src/Illuminate/Cookie/Guard.php(51): Illuminate\Cookie\Queue->handle(Object(Illuminate\Http\Request), 1, true) #9 /var/www/project_name/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Illuminate\Cookie\Guard->handle(Object(Illuminate\Http\Request), 1, true) #10 /var/www/project_name/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(641): Stack\StackedHttpKernel->handle(Object(Illuminate\Http\Request)) #11 /var/www/project_name/public/index.php(49): Illuminate\Foundation\Application->run() #12 {main} [] []

Saikishore's avatar

Hi... Finally i got it.... I used "any" instead of "post". Thanks for all your support

bashy's avatar

Do you only want to POST to that route? Why use Route::any()?

Saikishore's avatar

@bashy, Yes I want post for that. I tried with "post". It is not working.. so I tried with any .. it works fine.. is there any other suggestions...?

bashy's avatar

You shouldn't need to use any if you only want to POST. Something must be set incorrectly if it's not picking it up.

In the error page, check what method is being used and report back.

kumar's avatar

hi when i use post method for image upload i got the following error

error:MethodNotAllowedHttpException in RouteCollection.php line 207:

my ajax code is; $(document).ready(function (e) { $("#uploadForm").on('submit',(function(e) { e.preventDefault(); var formData = new FormData($(this)[0]); $.ajax({ url: "upload", type: "post", data: formData, contentType: false, cache: false, processData:false, success: function(data) { $("#targetLayer").html(data); }, error: function() { }
}); })); });

my route; Route::post('upload','ImageUploadController@Upload');

what will i do?

kumar's avatar

@bashy,hi when i use post method for image upload i got the following error

error:MethodNotAllowedHttpException in RouteCollection.php line 207:

my ajax code is; $(document).ready(function (e) { $("#uploadForm").on('submit',(function(e) { e.preventDefault(); var formData = new FormData($(this)[0]); $.ajax({ url: "upload", type: "post", data: formData, contentType: false, cache: false, processData:false, success: function(data) { $("#targetLayer").html(data); }, error: function() { } }); })); });

my route; Route::post('upload','ImageUploadController@Upload');

what will i do?

kumar's avatar

@thomaskin I changed my code i directly upload thorough form and i include then i could upload in post method ...But when I change my session storage path "database" instead of "file" i get this following errror . ERROR:TokenMismatchException in VerifyCsrfToken.php line 46....................................

how to i fix it ?

Please or to participate in this conversation.