back()->withErrors($validator)->withInput();
<form method="post" action="/cart/finish">
@csrf
<label><b>*</b> Ваше имя</label>
<input class="form-control @error('name') is-invalid @enderror" name="name" value="{{old('name')}}">
@error('name') <div class="invalid-feedback"> {{ $message }} </div> @enderror
<label><b>*</b> Номер телефона</label>
<input class="form-control @error('phone') is-invalid @enderror" name="phone" value="{{old('phone')}}">
@error('phone') <div class="invalid-feedback"> {{ $message }} </div> @enderror
<label><b>*</b> E-mail</label>
<input class="form-control @error('email') is-invalid @enderror" name="email" value="{{old('email')}}">
@error('email') <div class="invalid-feedback"> {{ $message }} </div> @enderror
<label><b>*</b> Способ доставки</label>
<select name="delivery_method" class="form-control @error('delivery_method') is-invalid @enderror">
<option disabled selected></option>
<option value="1" @if(old('delivery_method')===1) selected @endif>Самовывоз</option>
<option value="2" @if(old('delivery_method')===2) selected @endif>Доставка курьером</option>
<option value="3" @if(old('delivery_method')===3) selected @endif>Почта России</option>
<option value="4" @if(old('delivery_method')===4) selected @endif>ТК "СДЭК" (До двери)</option>
<option value="5" @if(old('delivery_method')===5) selected @endif>ТК "СДЭК" (до пункта выдачи)</option>
</select>
@error('delivery_method') <div class="invalid-feedback"> {{ $message }} </div> @enderror
<label><b>*</b> Форма оплаты</label>
<select name="payment_method" class="form-control @error('payment_method') is-invalid @enderror">
<option disabled selected></option>
<option value="1" @if(old('delivery_method')===1) selected @endif>Наличными при получении</option>
<option value="2" @if(old('delivery_method')===2) selected @endif>На карту Сбербанка</option>
<option value="3" @if(old('delivery_method')===3) selected @endif>Безналичная оплата по счету</option>
</select>
@error('payment_method') <div class="invalid-feedback"> {{ $message }} </div> @enderror
<label>Адрес доставки</label>
<textarea name="delivery_address" class="form-control @error('delivery_address') is-invalid @enderror">{{old('delivery_address')}}</textarea>
@error('delivery_address') <div class="invalid-feedback"> {{ $message }} </div> @enderror
<label>Комментарий к заказу</label>
<textarea name="comment" class="form-control @error('comment') is-invalid @enderror">{{old('comment')}}</textarea>
@error('comment') <div class="invalid-feedback"> {{ $message }} </div> @enderror
</form>
public function cart_finish(Request $request) {
$validator = Validator::make($request->all(), [
'name' => 'required|max:60',
'phone' => 'required|max:20',
'email' => 'required|email|max:60',
'delivery_method' => 'required|integer',
'payment_method' => 'required|integer',
'delivery_address' => 'max:300',
'comment' => 'max:300',
]);
if ($validator->fails()) {
return back()
->withErrors($validator)
->withInput();
}
public function cart_checkout(Request $request) {
$cart = Order::getCart();
return view('cart_checkout', [
'website' => Website::instance(),
'cart' => $cart
]);
}
'required' => 'Поле ":attribute" обязательно для заполнения.',
'required' => 'Заполни ":attribute"',