【发布时间】:2018-02-06 17:19:08
【问题描述】:
我将 laravel 的收银员与 Invoices 集合中的条纹和结合使用,我正在尝试通过其 subscription 键检索特定发票:
Collection {#157 ▼
#items: array:1 [▼
0 => Invoice {#162 ▼
#owner: User {#163 ▶}
#invoice: Invoice {#208 ▼
+"id": "in_1BsZF2F3eLup6dYnvs74ij6B"
+"object": "invoice"
...
+"statement_descriptor": null
+"subscription": "sub_CH7UxbgcTCeHLp"
+"subtotal": 1999
+"tax": null
+"tax_percent": null
+"total": 1999
+"webhooks_delivered_at": 1517934260
}
}
]
}
这是user 模型用来检索其Invoices 集合的函数:
public function invoices($includePending = false, $parameters = [])
{
$invoices = [];
$parameters = array_merge(['limit' => 24], $parameters);
$stripeInvoices = $this->asStripeCustomer()->invoices($parameters);
// Here we will loop through the Stripe invoices and create our own custom Invoice
// instances that have more helper methods and are generally more convenient to
// work with than the plain Stripe objects are. Then, we'll return the array.
if (! is_null($stripeInvoices)) {
foreach ($stripeInvoices->data as $invoice) {
if ($invoice->paid || $includePending) {
$invoices[] = new Invoice($this, $invoice);
}
}
}
return new Collection($invoices);
}
每个Invoice 对象都有两个属性,Owner(当前用户)和实际的Invoice
向下钻取每个 Invoices subscription 键并检查该值的正确语法是什么?
我尝试了以下查询,结果为NULL:
$user->invoices()->where('subscription','sub_CH7UxbgcTCeHLp')->first();
更新
当我转储以下查询 $user->invoices()->first()->subscription 时,它会在 sub_CH7UxbgcTCeHLp 中返回正确的字符串,但是当我尝试使用 $user->invoices()->firstWhere('subscription', 'sub_CH7UxbgcTCeHLp') 对其进行检查时,它的结果是 NULL
【问题讨论】:
标签: php laravel object eloquent