20
app/Http/Controllers/LocaleController.php
Normal file
20
app/Http/Controllers/LocaleController.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class LocaleController extends Controller
|
||||
{
|
||||
public function __invoke(Request $request, string $locale): RedirectResponse
|
||||
{
|
||||
$supportedLocales = array_keys((array) config('app.supported_locales', []));
|
||||
|
||||
abort_unless(in_array($locale, $supportedLocales, true), 404);
|
||||
|
||||
$request->session()->put('locale', $locale);
|
||||
|
||||
return back();
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,6 @@ class AccountController extends Controller
|
||||
|
||||
$request->user()->update($validated);
|
||||
|
||||
return back()->with('status', 'Данные профиля обновлены.');
|
||||
return back()->with('status', __('Данные профиля обновлены.'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ class AuthController extends Controller
|
||||
if (!$this->captchaIsValid($request, self::LOGIN_CAPTCHA_CONTEXT)) {
|
||||
return back()
|
||||
->withInput($request->only('email', 'remember'))
|
||||
->withErrors(['captcha' => 'Неверный ответ на капчу.']);
|
||||
->withErrors(['captcha' => __('Неверный ответ на капчу.')]);
|
||||
}
|
||||
|
||||
$credentials = [
|
||||
@@ -47,7 +47,7 @@ class AuthController extends Controller
|
||||
if (!Auth::attempt($credentials, $remember)) {
|
||||
return back()
|
||||
->withInput($request->only('email', 'remember'))
|
||||
->withErrors(['email' => 'Неверный email или пароль.']);
|
||||
->withErrors(['email' => __('Неверный email или пароль.')]);
|
||||
}
|
||||
|
||||
$request->session()->regenerate();
|
||||
@@ -75,7 +75,7 @@ class AuthController extends Controller
|
||||
if (!$this->captchaIsValid($request, self::REGISTER_CAPTCHA_CONTEXT)) {
|
||||
return back()
|
||||
->withInput($request->only('name', 'email'))
|
||||
->withErrors(['captcha' => 'Неверный ответ на капчу.']);
|
||||
->withErrors(['captcha' => __('Неверный ответ на капчу.')]);
|
||||
}
|
||||
|
||||
$user = User::create([
|
||||
|
||||
@@ -46,20 +46,20 @@ class CartController extends Controller
|
||||
public function add(Product $product)
|
||||
{
|
||||
if (!$product->is_active || $product->stock < 1) {
|
||||
return back()->with('status', 'Товар сейчас недоступен для заказа.');
|
||||
return back()->with('status', __('Товар сейчас недоступен для заказа.'));
|
||||
}
|
||||
|
||||
$cart = (array) session()->get('cart', []);
|
||||
$current = (int) ($cart[$product->id] ?? 0);
|
||||
|
||||
if ($current >= $product->stock) {
|
||||
return back()->with('status', 'В корзине уже максимальное доступное количество.');
|
||||
return back()->with('status', __('В корзине уже максимальное доступное количество.'));
|
||||
}
|
||||
|
||||
$cart[$product->id] = $current + 1;
|
||||
session()->put('cart', $cart);
|
||||
|
||||
return back()->with('status', "Товар \"{$product->name}\" добавлен в корзину.");
|
||||
return back()->with('status', __('Товар ":name" добавлен в корзину.', ['name' => $product->name]));
|
||||
}
|
||||
|
||||
public function update(Request $request, Product $product)
|
||||
@@ -80,15 +80,15 @@ class CartController extends Controller
|
||||
unset($cart[$product->id]);
|
||||
session()->put('cart', $cart);
|
||||
|
||||
return back()->with('status', "Товар \"{$product->name}\" удален из корзины.");
|
||||
return back()->with('status', __('Товар ":name" удален из корзины.', ['name' => $product->name]));
|
||||
}
|
||||
|
||||
$cart[$product->id] = $quantity;
|
||||
session()->put('cart', $cart);
|
||||
|
||||
$message = $quantity < (int) $validated['quantity']
|
||||
? 'Количество ограничено текущим остатком.'
|
||||
: 'Количество товара обновлено.';
|
||||
? __('Количество ограничено текущим остатком.')
|
||||
: __('Количество товара обновлено.');
|
||||
|
||||
return back()->with('status', $message);
|
||||
}
|
||||
@@ -101,6 +101,6 @@ class CartController extends Controller
|
||||
session()->put('cart', $cart);
|
||||
}
|
||||
|
||||
return back()->with('status', "Товар \"{$product->name}\" удален из корзины.");
|
||||
return back()->with('status', __('Товар ":name" удален из корзины.', ['name' => $product->name]));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ class ChatController extends Controller
|
||||
$messageText = $this->sanitizeMessage((string) $validated['message']);
|
||||
if ($messageText === '') {
|
||||
throw ValidationException::withMessages([
|
||||
'message' => 'Сообщение содержит недопустимые символы.',
|
||||
'message' => __('Сообщение содержит недопустимые символы.'),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ class ChatController extends Controller
|
||||
'status' => $conversation->status,
|
||||
'is_closed' => $conversation->isClosed(),
|
||||
'notice' => $conversation->isClosed()
|
||||
? 'Чат закрыт администратором. Отправьте новое сообщение, чтобы начать новый диалог.'
|
||||
? __('Чат закрыт администратором. Отправьте новое сообщение, чтобы начать новый диалог.')
|
||||
: null,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ class CheckoutController extends Controller
|
||||
$items = $this->cartItems($request);
|
||||
|
||||
if ($items->isEmpty()) {
|
||||
return redirect()->route('cart.index')->with('status', 'Корзина пустая. Добавьте товары перед оформлением.');
|
||||
return redirect()->route('cart.index')->with('status', __('Корзина пустая. Добавьте товары перед оформлением.'));
|
||||
}
|
||||
|
||||
return view('shop.checkout', [
|
||||
@@ -34,7 +34,7 @@ class CheckoutController extends Controller
|
||||
$items = $this->cartItems($request);
|
||||
|
||||
if ($items->isEmpty()) {
|
||||
return redirect()->route('cart.index')->with('status', 'Корзина пустая. Добавьте товары перед оформлением.');
|
||||
return redirect()->route('cart.index')->with('status', __('Корзина пустая. Добавьте товары перед оформлением.'));
|
||||
}
|
||||
|
||||
$validated = $request->validate([
|
||||
@@ -56,12 +56,12 @@ class CheckoutController extends Controller
|
||||
$items = $this->cartItems($request);
|
||||
|
||||
if ($items->isEmpty()) {
|
||||
return redirect()->route('cart.index')->with('status', 'Корзина пустая. Добавьте товары перед оформлением.');
|
||||
return redirect()->route('cart.index')->with('status', __('Корзина пустая. Добавьте товары перед оформлением.'));
|
||||
}
|
||||
|
||||
$customer = $request->session()->get(self::CHECKOUT_CUSTOMER_KEY);
|
||||
if (!is_array($customer)) {
|
||||
return redirect()->route('checkout.show')->with('status', 'Сначала заполните данные получателя.');
|
||||
return redirect()->route('checkout.show')->with('status', __('Сначала заполните данные получателя.'));
|
||||
}
|
||||
|
||||
return view('shop.checkout-payment', [
|
||||
@@ -77,12 +77,12 @@ class CheckoutController extends Controller
|
||||
$items = $this->cartItems($request);
|
||||
|
||||
if ($items->isEmpty()) {
|
||||
return redirect()->route('cart.index')->with('status', 'Корзина пустая. Добавьте товары перед оформлением.');
|
||||
return redirect()->route('cart.index')->with('status', __('Корзина пустая. Добавьте товары перед оформлением.'));
|
||||
}
|
||||
|
||||
$validated = $request->session()->get(self::CHECKOUT_CUSTOMER_KEY);
|
||||
if (!is_array($validated)) {
|
||||
return redirect()->route('checkout.show')->with('status', 'Сначала заполните данные получателя.');
|
||||
return redirect()->route('checkout.show')->with('status', __('Сначала заполните данные получателя.'));
|
||||
}
|
||||
|
||||
$validator = validator($validated, [
|
||||
|
||||
@@ -44,24 +44,24 @@ class CompareController extends Controller
|
||||
$compare = array_values(array_filter($compare, fn (int $id) => $id !== $product->id));
|
||||
session()->put('compare', $compare);
|
||||
|
||||
return back()->with('status', "Товар \"{$product->name}\" удален из сравнения.");
|
||||
return back()->with('status', __('Товар ":name" удален из сравнения.', ['name' => $product->name]));
|
||||
}
|
||||
|
||||
if (count($compare) >= 4) {
|
||||
return back()->with('status', 'Можно сравнить не более 4 товаров одновременно.');
|
||||
return back()->with('status', __('Можно сравнить не более 4 товаров одновременно.'));
|
||||
}
|
||||
|
||||
$compare[] = $product->id;
|
||||
session()->put('compare', array_values(array_unique($compare)));
|
||||
|
||||
return back()->with('status', "Товар \"{$product->name}\" добавлен в сравнение.");
|
||||
return back()->with('status', __('Товар ":name" добавлен в сравнение.', ['name' => $product->name]));
|
||||
}
|
||||
|
||||
public function clear()
|
||||
{
|
||||
session()->forget('compare');
|
||||
|
||||
return back()->with('status', 'Список сравнения очищен.');
|
||||
return back()->with('status', __('Список сравнения очищен.'));
|
||||
}
|
||||
|
||||
private function compareIds(): array
|
||||
|
||||
@@ -24,7 +24,7 @@ class ContactController extends Controller
|
||||
if ($botToken === '' || $chatId === '') {
|
||||
return back()
|
||||
->withInput()
|
||||
->withErrors(['contact' => 'Не настроена отправка в Telegram. Заполните SHOP_TELEGRAM_BOT_TOKEN и SHOP_TELEGRAM_CHAT_ID.']);
|
||||
->withErrors(['contact' => __('Не настроена отправка в Telegram. Заполните SHOP_TELEGRAM_BOT_TOKEN и SHOP_TELEGRAM_CHAT_ID.')]);
|
||||
}
|
||||
|
||||
$message = $this->buildTelegramMessage($validated, $request);
|
||||
@@ -41,16 +41,16 @@ class ContactController extends Controller
|
||||
} catch (Throwable) {
|
||||
return back()
|
||||
->withInput()
|
||||
->withErrors(['contact' => 'Не удалось отправить заявку в Telegram. Попробуйте еще раз.']);
|
||||
->withErrors(['contact' => __('Не удалось отправить заявку в Telegram. Попробуйте еще раз.')]);
|
||||
}
|
||||
|
||||
if (!$response->successful() || $response->json('ok') !== true) {
|
||||
return back()
|
||||
->withInput()
|
||||
->withErrors(['contact' => 'Telegram не принял заявку. Проверьте токен бота и chat id.']);
|
||||
->withErrors(['contact' => __('Telegram не принял заявку. Проверьте токен бота и chat id.')]);
|
||||
}
|
||||
|
||||
return back()->with('status', 'Заявка отправлена. Мы свяжемся с вами в ближайшее время.');
|
||||
return back()->with('status', __('Заявка отправлена. Мы свяжемся с вами в ближайшее время.'));
|
||||
}
|
||||
|
||||
private function buildTelegramMessage(array $data, Request $request): string
|
||||
|
||||
@@ -34,13 +34,13 @@ class FavoriteController extends Controller
|
||||
$favorites = array_values(array_filter($favorites, fn (int $id) => $id !== $product->id));
|
||||
session()->put('favorites', $favorites);
|
||||
|
||||
return back()->with('status', "Товар \"{$product->name}\" удален из избранного.");
|
||||
return back()->with('status', __('Товар ":name" удален из избранного.', ['name' => $product->name]));
|
||||
}
|
||||
|
||||
$favorites[] = $product->id;
|
||||
session()->put('favorites', array_values(array_unique($favorites)));
|
||||
|
||||
return back()->with('status', "Товар \"{$product->name}\" добавлен в избранное.");
|
||||
return back()->with('status', __('Товар ":name" добавлен в избранное.', ['name' => $product->name]));
|
||||
}
|
||||
|
||||
private function favoriteIds(): array
|
||||
|
||||
Reference in New Issue
Block a user