Murugesan Rathinam
Murugesan Rathinam

Reputation: 158

Post method not working in laravel 5.4 from web route

POST method not working in laravel 5.4 , GET method is working same controller.

 Route::get('/route','PostController@custon_function'); //working

 Route::post('/route','PostController@custon_function'); //throw error

enter image description here

Upvotes: 0

Views: 532

Answers (1)

M_Idrees
M_Idrees

Reputation: 2172

Option 1

You can combine GET and POST method with one route this way:

Route::match(array('GET','POST'),'/route','PostController@custom_function');

Option 2

Or you can use this alternative:

Route::any('/route', 'PostController@custom_function');

And within controller/function, you can check method name this way:

if (Request::isMethod('post'))
{
// ... this is POST method
}
if (Request::isMethod('get'))
{
// ... this is GET method
}

Upvotes: 1

Related Questions