【问题标题】:Column not found: 1054 Champ 'payment_gateway' inconnu dans field list using laravel未找到列:1054 Champ 'payment_gateway' inconnu dans field list using laravel
【发布时间】:2020-09-13 17:55:18
【问题描述】:

我使用 laravel 进行了电子商务培训,我想通过 paypal 购物车进行在线支付,但它在表订单的字段 payment_gatewayColumn not found: 1054 Field 'payment_gateway' unknown in field list 中出现错误。

您好,我参加了一个使用 laravel 的电子商务培训,我想通过 paypal 购物车进行在线支付,但它在表订单的payment_gatewayColumn not found: 1054 Field 'payment_gateway' unknown in field list 字段中给了我错误。

checkoutController.php

/**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function paypalCheckout(Request $request)
    {
        // Check race condition when there are less items available to purchase
        if ($this->productsAreNoLongerAvailable()) {
            return back()->withErrors('Sorry! One of the items in your cart is no longer avialble.');
        }
        $gateway = new \Braintree\Gateway([
            'environment' => config('services.braintree.environment'),
            'merchantId' => config('services.braintree.merchantId'),
            'publicKey' => config('services.braintree.publicKey'),
            'privateKey' => config('services.braintree.privateKey')
        ]);
        $nonce = $request->payment_method_nonce;
        $result = $gateway->transaction()->sale([
            'amount' => round(getNumbers()->get('newTotal') / 100, 2),
            'paymentMethodNonce' => $nonce,
            'options' => [
                'submitForSettlement' => true
            ]
        ]);
        $transaction = $result->transaction;
        if ($result->success) {
            $order = $this->addToOrdersTablesPaypal(
                $transaction->paypal['payerEmail'],
                $transaction->paypal['payerFirstName'].' '.$transaction->paypal['payerLastName'],
                null
            );
            Mail::send(new OrderPlaced($order));
            // decrease the quantities of all the products in the cart
            $this->decreaseQuantities();
            Cart::instance('default')->destroy();
            session()->forget('coupon');

            return redirect()->route('confirmation.index')->with('success_message', 'Thank you! Your payment has been successfully accepted!');
        } else {
            $order = $this->addToOrdersTablesPaypal(
                $transaction->paypal['payerEmail'],
                $transaction->paypal['payerFirstName'].' '.$transaction->paypal['payerLastName'],
                $result->message
            ); 
            return back()->withErrors('An error occurred with the message: '.$result->message);
        }
    }

函数 addToOrdersTablesPaypal

protected function addToOrdersTablesPaypal($email, $name, $error)
    {
        // Insert into orders table
        $order = Order::create([
            'user_id' => auth()->user() ? auth()->user()->id : null,
            'billing_email' => $email,
            'billing_name' => $name,
            'billing_discount' => getNumbers()->get('discount'),
            'billing_discount_code' => getNumbers()->get('code'),
            'billing_subtotal' => getNumbers()->get('newSubtotal'),
            'billing_tax' => getNumbers()->get('newTax'),
            'billing_total' => getNumbers()->get('newTotal'),
            'error' => $error,
            'payment_gateway' => 'paypal',
        ]);

        // Insert into order_product table
        foreach (Cart::content() as $item) {
            OrderProduct::create([
                'order_id' => $order->id,
                'product_id' => $item->model->id,
                'quantity' => $item->qty,
            ]);
        }

        return $order;
    }

订单表

错误

【问题讨论】:

  • 错误是不言自明的。 orders 表没有 payment_gateway 列。

标签: php laravel paypal


【解决方案1】:

输入payement_gateway => payment_gateway时似乎是一个错字

【讨论】:

    【解决方案2】:

    确保:

    1- 将 payment_gateway 添加到 Order 模型的可填充数组中

    2-payment_gateway 列在表“订单”列中...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-09-28
      • 1970-01-01
      • 2015-02-22
      • 2020-05-13
      • 2021-08-08
      • 2019-11-11
      相关资源
      最近更新 更多