lko*_*ger 2 laravel stripe-payments laravel-4
我对 Taylor ( https://github.com/laravel/cashier )的收银员包有问题。当我尝试获取用户的发票时,返回的对象为空。有关信息,我已将我的收银员数据库列设置到会员表中!然后建立适当的关系。如果我这样做,我可以向用户收费:
$user->membership->subscription('1month')->create($token);
Run Code Online (Sandbox Code Playgroud)
但如果我想像这样拿到发票
$invoices = $user->membership->invoices();
Run Code Online (Sandbox Code Playgroud)
它返回一个空对象。
我究竟做错了什么??
谢谢
更新:这是模型中的代码:
User.php
public function membership() {
return $this->hasOne('Membership');
}
Run Code Online (Sandbox Code Playgroud)
和
Membership.php
class Membership extends \Eloquent implements BillableInterface {
use BillableTrait;
/**
* @var array
*/
protected $dates = ['trial_ends_at', 'subscription_ends_at'];
public function user_membership() {
return $this->belongsTo('User');
}
}
Run Code Online (Sandbox Code Playgroud)
如果您将其作为 JSON 或类似格式提取,这可能是从控制器返回的有用片段:
public function index()
{
$user = auth()->user();
if($user->hasStripeId()) {
$invoices = $user->invoices()->map(function($invoice) {
return [
'date' => $invoice->date()->toFormattedDateString(),
'total' => $invoice->total,
'download' => '/user/download/invoice/' . $invoice->id,
];
});
} else {
$invoices = [];
}
return [ 'invoices' => $invoices ];
}
Run Code Online (Sandbox Code Playgroud)
在 Cashier v7.x 中测试
| 归档时间: |
|
| 查看次数: |
2900 次 |
| 最近记录: |