use Request;
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
In app/Exceptions/Handler.php replace render function
public function render($request, Exception $exception)
{
if (Request::isMethod('post') && $exception instanceof MethodNotAllowedHttpException) {
return response()->json([
'message' => 'Page Not Found',
'status' => false
], 500
);
}
return parent::render($request, $exception);
}
Or if you want both NotFound And MethodNotAllowed then
public function render($request, Exception $exception)
{
if ((Request::isMethod('post') && $exception instanceof MethodNotAllowedHttpException) || (Request::isMethod('post') && $exception instanceof NotFoundHttpException)) {
return response()->json([
'message' => 'Page Not Found',
'status' => false
], 500
);
}
return parent::render($request, $exception);
}