0

我正在使用 Laravel 8 构建一个电子商务网站,并且我正在尝试将实时运费与 Shippo API 结合起来。我能够通过作曲家安装 Shippo,但我收到一个错误,说争论太少或未定义变量。我从有关 Shippo 的文章中借用了一些代码,但我不断收到错误消息。你有类似的问题吗?你解决了吗?任何帮助表示赞赏。这是我的控制器代码,

<?php

namespace App\Http\Controllers\User;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\ShipDivision;
use App\Models\ShipDistrict;
use App\Models\ShipState;
use App\Models\Product;
use App\Services\Shipping_New;
use App\Models\User;
use Auth;
use\App\Http\Controllers\Frontend\CartController;
use Gloudemans\Shoppingcart\Facades\Cart;
use Carbon\Carbon;

class CheckoutController extends Controller
{

  /**
   * @var Shipping
   */
  private $shipping;

  /**
   * @var UserRepository
   */
  private $user;

  /**
   * CheckoutController constructor.
   * @param UserRepository $user
   * @param Shipping $shipping
   */
  public function __construct(User $user, Shipping_New $shipping)
  {
      $this->middleware('auth');
      $this->shipping = $shipping;
      $this->user = $user;
  }

  public function DistrictGetAjax($division_id) {

    $ship = ShipDistrict::where('division_id',$division_id)->orderBy('district_name', 'ASC')->get();

    return json_encode($ship);

  }

  public function StateGetAjax($district_id) {

    $ship = ShipState::where('district_id',$district_id)->orderBy('state_name', 'ASC')->get();

    return json_encode($ship);

  }

  public function CheckoutStore(Request $request) {

    $data = array();
    $data['name'] = $request->name;
    $data['shipping_last_name'] = $request->shipping_last_name;
    $data['email'] = $request->email;
    $data['phone'] = $request->phone;
    $data['zip'] = $request->zip;
    $data['street1'] = $request->street1;
    $data['company'] = $request->company;
    $data['city'] = $request->city;
    $data['country'] = $request->country;
    $data['notes'] = $request->notes;
    $data['state_id'] = $request->state_id;
    $data['district_id'] = $request->district_id;
    $data['division_id'] = $request->division_id;
    $cartTotal = Cart::total();
    // The rates is a complete object but for this we
    // only need the rates_list items and will pass that.


    if ($request->payment_method == 'stripe') {


      return view('online-boutique-stores.payment.stripe', compact('data','cartTotal'));


    }

      elseif ($request->payment_method == 'paypal') {

        $carts = Cart::content();
        $cartQty = Cart::count();
        $cartTotal = Cart::total();

        return view('online-boutique-stores.payment.paypal', compact('data', 'cartTotal'));

      }

      else {

        return 'cash';

      }

  }

}
4

1 回答 1

0

删除这个你的构造参数。因为您看不到这些论点有任何用处。你可以用这种方式吗?

public function __construct()

{ $this->middleware('auth');

}

于 2021-10-07T02:11:54.067 回答