【发布时间】:2019-10-28 19:15:12
【问题描述】:
我在 Laravel 中创建了一个 trait。
在 myconstruct 中,我调用了一个 setting('value') - 这是由 qcod/laravel-app-settings 包提供的。
但在我的方法中,当我引用 $this->token 或 $this->org_id 时,它会返回 NULL
我知道这些值已设置,因为它们在配置中显示并且也在数据库中正确设置。
我的 PHP 代码是:
<?php
namespace App\Traits;
use Illuminate\Support\Facades\Log;
trait PropertyBaseTrait
{
private $org_id;
private $token;
private $is_set;
public function __construct()
{
$this->org_id = setting('propertybase_org');
$this->token = setting('propertybase_token');
}
public function base_url($method)
{
return 'https://pb-integrations-api-staging.herokuapp.com/api/v1/'.$method.'/'.$this->org_id.'';
}
public function post_lead($data)
{
$lead_data = array(
'first_name' => '',
'last_name' => '',
'email' => '',
'phone1' => '',
'phone2' => '',
'phone3' => '',
'address' => '',
'city' => '',
'state' => '',
'zip_code' => '',
'country_name' => '',
'landing_page' => '',
'search_term' => '',
'referral_source' => ''
);
$object_type = 'lead';
$action_type = 'create';
dd($this->token);
$endpoint = $this->base_url('messages');
$this->post_data( $endpoint, $object_type, $action_type, json_encode($data));
}
【问题讨论】: