Что-то вроде:
public function index(Request $request)
{
$req_body = (json_decode($request->getContent(), true));
// Collect all available methods here:
$methods = ['init', 'login', 'requestOtp']; // etc
// if method name is in the collection - call this method
if (in_array($req_body['action'], $methods)) {
return $this->{$req_body['action']}($req_body['data']);
}
return response()->json([
'error' => true,
'message' => 'Invalid action',
'data' => (object)null,
]);
}