ORHAN ERDAY
ORHAN ERDAY

Reputation: 1066

Redirecting To Controller Actions with POST method in laravel 6

I have an action named destroy in UserController I don't wanna work this action instead of UserInfoController@destroy supposed to run. So I need to redirect to the UserInfoControlle@destroy controller.

UserController@destroy action;

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

Action successfully ran but I get this error;

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

Upvotes: 1

Views: 98

Answers (1)

Babak Asadzadeh
Babak Asadzadeh

Reputation: 1239

you have some way to do that like below:

  1. make new get route for that

    Route::get('/delete/{id}','UserInfoController@destroy')->name('deleteWithGetMethod');
    
  2. change post to any in your route

    Route::any('/delete/{id}','UserInfoController@destroy')->name('delete');
    
  3. return a view that contains below code

    <form id="myForm" action="{{ route('delete',$userInfoId) }}" method="post">
    </form>
    <script type="text/javascript">
        document.getElementById('myForm').submit();
    </script>
    

Upvotes: 1

Related Questions