Krishan Kumawat
Krishan Kumawat

Reputation: 29

if request is not post then to redirect to another route

 $checkMethod = $request->method();
        if (!$checkMethod) {
            return redirect('todo_show');
        } else {
            echo "yes";
        }

if request is not post then how can i redirect to another route. This error occured "The GET method is not supported for this route. Supported methods: POST".

Upvotes: 0

Views: 392

Answers (1)

STA
STA

Reputation: 34688

Change your route Route::post... to Route::any... or Route::match(['GET', 'POST')]… And as per Laravel documentation you can check this request method on your controller :

$method = $request->method();
if ($request->isMethod('post')) {
    return redirect('todo_show');
} else {
    echo "yes";
}

Upvotes: 1

Related Questions