61 lines
1.5 KiB
PHP
61 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\UserPaymentOptionStatus;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
class UserPaymentOption extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $fillable = [
|
|
'user_id',
|
|
'payment_option_id',
|
|
'status',
|
|
'grandfathered_until',
|
|
'legacy_conditions',
|
|
'current_period_start',
|
|
'current_period_end',
|
|
'stripe_subscription_id',
|
|
'cancelled_at',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'status' => UserPaymentOptionStatus::class,
|
|
'grandfathered_until' => 'date',
|
|
'legacy_conditions' => 'array',
|
|
'current_period_start' => 'date',
|
|
'current_period_end' => 'date',
|
|
'cancelled_at' => 'datetime',
|
|
];
|
|
}
|
|
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public function paymentOption(): BelongsTo
|
|
{
|
|
return $this->belongsTo(PaymentOption::class);
|
|
}
|
|
|
|
public function companies(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(Company::class, 'user_payment_option_company')
|
|
->withPivot('is_active')
|
|
->withTimestamps();
|
|
}
|
|
|
|
public function payments(): HasMany
|
|
{
|
|
return $this->hasMany(UserPayment::class);
|
|
}
|
|
}
|