我正在尝试提交结帐表格,但未提交。它具有购物车(产品名称,代码,价格)和当前输入的用户数据的产品值,以及数据库表(订单)https://ibb.co/bbBHCky的屏幕快照……解决该问题的任何解决方案,.... ...... ,,,,,,,。
checkout.blade.php
<ul class="list-group mb-3">
<?php $total_amount = 0; ?>
@foreach($userCart as $cart)
<li class="list-group-item d-flex justify-content-between lh-condensed">
<div>
<h6 class="my-0">{{ $cart->product_name }}</h6>
<small class="text-muted">Quantity: {{ $cart->quantity }}</small>
<small class="text-muted" style="display: none;">{{ $cart->product_code }}</small>
<small class="text-muted" style="display: none;">{{ $cart->product_id }}</small>
</div>
<span class="text-muted">Rs {{ $cart->price }}</span>
</li>
@endforeach
<li class="list-group-item d-flex justify-content-between">
<span>Total (PKR)</span>
<strong>{{ $total }}</strong>
</li>
</ul>
<form method="post" action="{{ url('/checkout') }}" class="needs-validation" novalidate>{{ csrf_field() }}
<div class="row">
<div class="col-md-6 mb-3">
<label for="firstName">Name</label>
<input type="text" name="name" class="form-control" id="firstName" placeholder="name" value="" required
style="border: 1px solid black !important;">
<div class="invalid-feedback">
Valid first name is required.
</div>
</div>
</div>
<div class="mb-3">
<label for="email">Email </label>
<input type="email" name="email" class="form-control" id="email" placeholder="you@example.com"
required="required" style="border: 1px solid black !important;">
<div class="invalid-feedback">
Please enter a valid email address for shipping updates.
</div>
</div>
<div class="mb-3">
<label for="address">Address</label>
<input type="text" name="address" class="form-control" id="address" placeholder="1234 Main St" required
style="border: 1px solid black !important;">
<div class="invalid-feedback">
Please enter your shipping address.
</div>
</div>
<div class="row">
<div class="col-md-5 mb-3">
<label for="country">Country</label>
<select name="country" class="custom-select d-block w-100" id="country" required>
<option value="">Choose...</option>
<option value="usa">United States</option>
</select>
<div class="invalid-feedback">
Please select a valid country.
</div>
</div>
<div class="col-md-4 mb-3">
<label for="state">State</label>
<select name="state" class="custom-select d-block w-100" id="state" required>
<option value="">Choose...</option>
<option value="cal">California</option>
</select>
<div class="invalid-feedback">
Please provide a valid state.
</div>
</div>
<div class="col-md-5 mb-3">
<label for="country">City</label>
<select name="city" class="custom-select d-block w-100" id="country" required>
<option value="">Choose...</option>
<option value="lhr">United States</option>
</select>
<div class="invalid-feedback">
Please select a valid country.
</div>
</div>
<div class="col-md-3 mb-3">
<label for="zip">Zip</label>
<input type="text" name="zipcode" class="form-control" id="zip" placeholder="" required
style="border: 1px solid black !important;">
<div class="invalid-feedback">
Zip code required.
</div>
</div>
<div class="col-md-5 mb-3">
<label for="zip">Mobile</label>
<input type="text" name="mobile" class="form-control" id="zip" placeholder="" required
style="border: 1px solid black !important;">
<div class="invalid-feedback">
mobile no required.
</div>
</div>
</div>
<button class="btn btn-primary btn-lg btn-block" type="submit" style="background-color: black;">Place Order</button>
</form>
ProductsController
public function placeOrder(Request $request)
{
if ($request->isMethod('post')) {
$data = $request->all();
$session_id = Session::get('session_id');
if (empty($session_id)) {
$session_id = str_random(40);
Session::put('session_id', $session_id);
}
$order = new Order;
$order->id = $id;
$order->name = $name;
$order->email = $email;
$order->address = $address;
$order->country = $country;
$order->state = $state;
$order->city = $city;
$order->zipcode = $zipcode;
$order->mobile = $mobile;
$order->product_id = $product_id;
$order->product_code = $product_code;
$order->product_name = $product_name;
$order->product_price = $product_price;
$order->product_quantity = $qty;
$order->order_status = "New";
$order->grand_total = $data['grand_total'];
$order->save();
return view('products.checkout');
}
}
路线
Route::match(['get','post'],'/place-order','ProductsController@placeOrder');
答案 0 :(得分:1)
将表单操作更改为
<form method="post" action="{{ url('place-order') }}" class="needs-validation" novalidate>
并从路线“ / place-order”中删除空间
Route::match(['get','post'],'/place-order','ProductsController@placeOrder');