0

Im using this code from the current Laravel documentation

return redirect()->action(
    'UserController@profile', ['id' => 1]
);

And changed it to my own controller like this:

return redirect()->action('ProjectController@showProject',['id'=> 2]); 

My route: Route::get('/crm/project/{id}', 'ProjectController@showProject');

According to my F12 this is my request url http://127.0.0.1:8000/back/crm/project/2 Which is correct. But im getting the following error: 405 Method Not Allowed.

This is the start of my stacktrace:

{message: "", exception: "Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException",…}

Thanks in advance.

Edit: Added route.

3 Answers3

0

Redirections are always made using GET method. I assume in web.php you have this route defined using other HTTP method (for example PUT or POST) - that's why you are getting this error. Take a look at web.php file and make sure you are using GET method or make redirection to other url.

Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291
  • Im using the `GET` method on my route where i want to redirect to. Or do i have to use it on a `GET` route aswell? Because the Route im currently on is a `PUT` route.. Route i want to redirect to : `Route::get('/crm/project/{id}', 'ProjectController@showProject');` Route currently on : `Route::put('/crm/project/{id}', 'ProjectController@update');` – Armando van Oeffelen Jan 18 '19 at 20:11
0

This can be a tricky one.

I think you will need to change the method. Check your web.php for a declration for that route. also it is better to use a middleware group for your route.

This is simply sayng that your methode is not allowed caouse it has been declared with an another method.

Moubarak Hayal
  • 191
  • 1
  • 7
0

the problem you are getting because you have used the same function name for tow different methods one for get and one for put that why you are getting the error because you are passing action in redirect so its search for action and found that action with put method

use this for redirect

return redirect()->route('/back/crm/project/', ['id' => 1]);

One more thing i want to suggest you never use the rediraction in ajax request its not a good programing practises and it'll not work at all if you have put or post method in your ajax

make a succes response and refresh your location thats it

Shailendra Gupta
  • 1,054
  • 6
  • 15