Type error: Argument 1 passed to PayPal\Rest\ApiContext::setConfig() must be of the type array, null given, called in PaymentController.php on line 40

Type error: Argument 1 passed to PayPal\Rest\ApiContext::setConfig() must be of the type array, null given, called in PaymentController.php on line 40

我正在尝试将贝宝应用到我的网站中。 但是我收到了这个错误。

类型错误:传递给 PayPal\Rest\ApiContext::setConfig() 的参数 1 必须是数组类型,给定为空,在第 40 行的 D:\wamp64\www\vonservices\app\Http\Controllers\PaymentController.php 中调用. 这是我的控制器代码:

class PaymentController extends Controller
{
    private $_api_context;
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        //parent::__construct();

        /** setup PayPal api context **/
        $paypal_conf = \Config::get('paypal');
        $this->_api_context = new ApiContext(new OAuthTokenCredential($paypal_conf['client_id'], $paypal_conf['secret']));
        $this->_api_context->setConfig($paypal_conf['settings']);
    }
    /**
     * Show the application paywith paypalpage.
     *
     * @return \Illuminate\Http\Response
     */
    public function payWithPaypal()
    {
        return view('paywithpaypal');
    }
    /**
     * Store a details of payment with paypal.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */

  }

  ?>```


我知道很晚了,但我遇到了同样的问题。 运行

解决了我的问题
php artisan config:cache

瞧,它为我解决了所有问题。希望它也适用于其他人。

\Config::get('paypal') 是在配置中查找数据的旧方法。在使用之前尝试使用 config('paypal')php artisan config:cache