对不起如果我的帖子不清楚,这是我的第一次
以下是我使用此功能 Http status code 0 时显示的错误
这是我尝试用于购物车增加项目和减少项目的代码。我在laravel 5.5中使用
我尝试将代码放在这里但不知何故它没有工作所以我上传图像
Click here to see my code function
@extends('layouts.app')
@section('content')
<section id="cart_items">
<div class="container">
<div class="breadcrumbs">
<ol class="breadcrumb">
<li class="active">My Shopping Cart</li>
</ol>
</div>
<div class="table-responsive cart_info">
@if(Cart::count())
<table class="table table-condensed">
<thead>
<tr class="cart_menu">
<td class="image">Item</td>
<td class="description">Product Name</td>
<td class="price">Price</td>
<td class="quantity">Quantity</td>
<td class="total">Total</td>
<td></td>
</tr>
</thead>
<tbody>
@foreach(Cart::content() as $item)
<tr>
<td class="cart_product">
{{ $loop->index+1 }}
</td>
<td class="cart_description">
{{$item->name}}
{{--<p><img src="{{asset('images/'.$product->photo->file)}}"> </p>--}}
</td>
<td class="cart_price">
<p>${{$item->price}}</p>
</td>
<td class="cart_quantity">
<div class="cart_quantity_button">
<a class="cart_quantity_down" href='{{url("cartEdit?product_id=$item->id&decrease=1")}}'> - </a>
<input class="cart_quantity_input" type="text" name="quantity" value="{{$item->qty}}" autocomplete="off" size="2" readonly>
<a class="cart_quantity_up" href='{{url("cartEdit?product_id=$item->id&increment=1")}}'> + </a>
<a href='{{url("cartEdit?product_id=$item->id&remove_item=1")}}'><span class="glyphicon glyphicon-trash"></span></a>
</div>
</td>
<td class="cart_total">
<p class="cart_total_price">${{$item->subtotal}}</p>
</td>
<td class="cart_delete">
<a class="cart_quantity_delete" href=""><i class="fa fa-times"></i></a>
</td>
</tr>
@endforeach
<tr>
<td colspan="2"></td>
<td>Cart Total</td>
<td colspan="2">${{Cart::subtotal()}}</td>
<td></td>
</tr>
<tr>
<td colspan="3"></td>
<td colspan="2" ><div align="center"><a class="btn btn-danger update" href="{{url('clearCart')}}">Clear Cart</a>
<a class="btn btn-danger check_out" href="{{url('checkout')}}">Check Out</a></div></td>
<td></td>
</tr>
@else
<p>You have no items in the shopping cart</p>
@endif
</tbody>
</table>
</div>
</div>
</section> <!--/#cart_items-->
@endsection
当我运行代码并点击&#39; +&#39;,&#39; - &#39;按钮,它显示HTTP状态代码&#34; 0&#34;无效。我不知道它为什么表现出来
This is how my cart look like
这是我的购物车控制器
<?php
namespace App\Http\Controllers;
use App\Order;
use App\Product;
use Cart;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Request;
use function Sodium\compare;
use Symfony\Component\HttpFoundation\Response;
use Illuminate\Support\Collection;
class CartController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public function add(\Illuminate\Http\Request $request)
{
/*update/ add new item to cart*/
$input = $request->all();
if($file = $request->file('photo_id')) {
$name = time() . $file->getClientOriginalName();
$file->move('image', $name);
$photo = Photo::create(['file'=>$name]);
$input['photo_id'] = $photo->id;
}
if (Request::isMethod('post')) {
$product_id = Request::get('id');
$product = Product::find($product_id);
Cart::add(
[
'id' => $product_id,
'name' => $product->name,
'image' => $product->photo_id,
'qty' => 1,
'price' => $product->price
]
);
}
// dd(Cart::content());
return redirect('/products');
}
public function cart() {
//increment the quantity
if (Request::get('product_id') && (Request::get('increment')) == 1) {
$rowId = Cart::search(function ($cartItem, $rowId) {
return $cartItem->id === Request::get('product_id');
});
$item = Cart::get($rowId->keys()->first());
Cart::update($rowId->keys()->first(), $item->qty + 1);
}
//decrease the quantity
if (Request::get('product_id') && (Request::get('decrease')) == 1) {
$rowId = Cart::search(function ($cartItem, $rowId) {
return $cartItem->id === Request::get('product_id');
});
$item = Cart::get($rowId->keys()->first());
Cart::update($rowId->keys()->first(), $item->qty - 1);
}
//remove the item
if(Request::get('product_id')&&(Request::get('remove_item')==1)){
$rowId = Cart::search(function ($cartItem, $rowId) {
return $cartItem->id === Request::get('product_id');
});
Cart::remove($rowId->keys()->first());
}
return redirect('/cartView',compact('user','orders'));
}
public function checkout(){
$id = Auth::id();
$items=Cart::content();
$total=0;$orderID=0;
//return Order::all();
if(count(Order::all())) {
$orderID = Order::orderBy('orderID', 'desc')->first()->orderID +1;
}else{
$orderID = 1;
}
//return $orderID;
foreach ($items as $item){
//return $item->rowId;
$total += $item->subtotal;
Order::create([
'orderID'=>$orderID,
'userID' => $id,
'image' => $item->image,
'cartRowID' => $item->rowId,
'itemID' => $item->id,
'itemName' => $item->name,
'qty' => $item->qty,
'price' => $item->price,
'subtotal' => $item->subtotal,
'returnOrder'=>0,
]);
}
Cart::destroy();
return view('order')->with('items',$items)->with('total',$total);
}
}