public function index(Request $request)
{
// проверки
if ($request->input("type") == "bet" ||
$request->input("type") == "withdraw" ||
$request->input("type") !== "create")
{
if (!Auth::check()) {
return json_encode(["errors" => "Вы должны быть авторизованы"]);
}
}
if ($request->input("type") == "bet" ||
$request->input("type") == "create")
{
if (User::getUser()->balance < intval($request->input("bet")))
{
return json_encode(["errors" => "Недостаточно средств"]);
}
}
//
$game = $request->input("game");
switch ($game) {
case "dice":
$validator = Validator::make($request->all(), [
"bet" => "required|numeric|min:1|max:10000",
"coef" => "required|numeric|min:1.05|max:100",
]);
if ($validator->fails())
{
return json_encode(["errors" => $validator->errors()->first()]);
}
$this->bet = intval($request->input("bet"));
$this->coef = floatval($request->input("coef"));
return $this->dice();
break;
case "coin":
if ($request->input("type") !== "bet" && $request->input("type") !== "withdraw")
{
$validator = Validator::make($request->all(), [
"bet" => "required|numeric|min:1|max:15000",
]);
if ($validator->fails() && $request->input("type") !== "is_active")
{
return json_encode(["errors" => $validator->errors()->first()]);
}
}
$this->bet = intval($request->input("bet"));
$this->side = $request->input("side");
$this->type = $request->input("type");
return $this->coin();
break;
case "mines":
if (
$request->input("type") !== "bet" &&
$request->input("type") !== "get_coefs"
) {
$validator = Validator::make($request->all(), [
"bet" => "required|numeric|min:1|max:5000",
"mines" => "required|numeric|min:3|max:24",
]);
if ($validator->fails() &&
$request->input("type") !== "is_active" &&
$request->input("type") !== "withdraw")
{
return json_encode(["errors" => $validator->errors()->first(),]);
}
}
$this->bet = intval($request->input("bet"));
$this->mines = $request->input("mines");
$this->mine = $request->input("mine");
$this->type = $request->input("type");
return $this->mines();
break;
case "wheel":
$validator = Validator::make($request->all(), [
"bet" => "required|numeric|min:1"
]);
if ($validator->fails() && $request->input("type") == "create")
{
return json_encode(["errors" => $validator->errors()->first(),]);
}
$this->type = $request->input("type");
$this->color = $request->input("color");
$this->bet = $request->input("bet");
$this->game_id = $request->input("game_id");
return $this->wheel();
break;
case "bonus_wheel":
$this->type = $request->input("type");
return $this->wheel_bonus();
break;
default:
return "unknown game";
}
}
if ($request->input("type")
заменяй на switch case, тем более далее по тексту у тебя оно используется, пиши код хотя бы в одном стиле.