我已使用app/config/packages/lightshire/laravel/
在php artisan config:publish
内发布了配置文件。我正在尝试访问此
$client_id = Config::get('lightshire/laravel-paypal::client_id');
并且它返回的全部是array(0) { }
我的服务提供商
<?php
namespace Lightshire\Paypal;
use Illuminate\Support\ServiceProvider as IlluminateServiceProvider;
class PaypalServiceProvider extends IlluminateServiceProvider
{
protected $defer = false;
public function boot()
{
$this->package("lightshire/laravel-paypal");
include app_path()."/routes.php";
}
public function register()
{
$this->app["paypal"] = $this->app->share(function($app)
{
return new Paypal;
});
}
public function provides()
{
return array('paypal');
}
}
我的Paypal.php
<?php
namespace Lightshire\Paypal;
require base_path()."/vendor/autoload.php";
use App;
use Config;
class Paypal
{
private $creds = null;
private $token = null;
public function __construct()
{
// // $data = Paypal::launch();
// $this->creds = $data["creds"];
// $this->token = $data["token"];
}
public static function getTokenCreds()
{
$client_id = Config::get('lightshire/laravel-paypal::client_id');
$secret = Config::get('laravel-paypal:secret');
$mode = Config::get('laravel-paypal:mode');
$endPoint = Config::get('laravel-paypal:endpoint');
;
$headers = array(
// 'Authorization' => 'Basic '.$encodedID,
'Accept' => 'application/json',
'Accept-Language' => 'en_US'
);
$params = array(
'grant_type' => 'client_credentials'
);
$url = "https://api.sandbox.paypal.com/v1/oauth2/token";
dd($client_id);
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, $client_id.":".$secret);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
}
知道为什么吗?
答案 0 :(得分:5)
在服务提供商的注册方法中尝试此操作(您可能需要编辑配置的位置):
$this->app['config']->package('lightshire/laravel-paypal', __DIR__.'/../../config');
第二个参数是配置(待发布)的位置
然后您应该能够使用以下方式访问您的配置:
Config::get('laravel-paypal::client_id');