0

我正在尝试获取 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();
        });
    }

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

谢谢

4

0 回答 0