如何使用Laravel Cashier获取end_date?

时间:2017-04-28 17:00:13

标签: php laravel laravel-cashier

我正在尝试获取Stripe订阅的end_date。

我认为:

@if (Auth::user()->subscription('main')->onGracePeriod())
    <p> Your subscription will end on: {{ Auth::user()->subscribed('main')->ends_at }}</p>
@endif

显然这是行不通的,因为我得到了:

Call to a member function ends_at() on boolean

我的用户类:

class User extends Authenticatable
{
    use Notifiable, EntrustUserTrait, Billable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    protected $dates = [
        'trial_ends_at'
    ];
}

我的迁移让您对表格有所了解:

public function up()
    {
        Schema::table('users', function ($table) {
            $table->string('stripe_id')->nullable();
            $table->string('card_brand')->nullable();
            $table->string('card_last_four')->nullable();
            $table->timestamp('trial_ends_at')->nullable();
        });

        Schema::create('subscriptions', function ($table) {
            $table->increments('id');
            $table->integer('user_id');
            $table->string('name');
            $table->string('stripe_id');
            $table->string('stripe_plan');
            $table->integer('quantity');
            $table->timestamp('trial_ends_at')->nullable();
            $table->timestamp('ends_at')->nullable();
            $table->timestamps();
        });
    }

再次查找DB中订阅表中列出的end_date。我总是可以使用这个表查询它,但想知道是否有更好的解决方案。

由于

0 个答案:

没有答案