lots of progress
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Subscription extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'description',
|
||||
'price',
|
||||
'duration_days',
|
||||
'features',
|
||||
'min_score',
|
||||
'verification_interval_minutes',
|
||||
'is_active'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'features' => 'array',
|
||||
'is_active' => 'boolean',
|
||||
'price' => 'decimal:2',
|
||||
'duration_days' => 'integer',
|
||||
'min_score' => 'integer',
|
||||
'verification_interval_minutes' => 'integer'
|
||||
];
|
||||
|
||||
public function users()
|
||||
{
|
||||
return $this->hasMany(UserSubscription::class);
|
||||
}
|
||||
}
|
||||
@@ -45,4 +45,17 @@ class User extends Authenticatable
|
||||
'password' => 'hashed',
|
||||
];
|
||||
}
|
||||
|
||||
public function subscriptions()
|
||||
{
|
||||
return $this->hasMany(UserSubscription::class);
|
||||
}
|
||||
|
||||
public function activeSubscription()
|
||||
{
|
||||
return $this->subscriptions()
|
||||
->where('status', 'active')
|
||||
->where('expires_at', '>', now())
|
||||
->first();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class UserSubscription extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'subscription_id',
|
||||
'started_at',
|
||||
'expires_at',
|
||||
'status',
|
||||
'payment_id'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'started_at' => 'datetime',
|
||||
'expires_at' => 'datetime'
|
||||
];
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function subscription()
|
||||
{
|
||||
return $this->belongsTo(Subscription::class);
|
||||
}
|
||||
|
||||
public function isActive()
|
||||
{
|
||||
return $this->status === 'active' && $this->expires_at->isFuture();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user