php - Call a route of post method from laravel

I want to call a route of the post method from the Laravel API part i.e. not from the blade file.

this is my route

Route::post('/logout', [LogoutController::class, 'destroy'])->name('logout');

This is destroy function in LogoutController class

public function destroy(Request $request) {}

I have tried with the below code. But these are not working.

return redirect()->route('logout', ['request' => $request]);
return redirect()->route('logout', [$request]);
return redirect()->route('logout')->with('request', $request);

Note: The method should be post only. We can't change this to GET.

Thanks.

Answer

Solution:

POST methods cannot just be called like that. You can only redirect to GET routes. If you wish to perform a logout from your middleware, just call the Auth::logout() function from the middleware like you would in the controller function, and flush the session afterwards ($request->session()->invalidate();).

If you really want to use a POST method route, you'll have to use a client such as Guzzle

Source