Add all files
This commit is contained in:
61
extensions/Others/ComplianceTools/Models/SupportPin.php
Normal file
61
extensions/Others/ComplianceTools/Models/SupportPin.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace Paymenter\Extensions\Others\ComplianceTools\Models;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class SupportPin extends Model
|
||||
{
|
||||
protected $table = 'ext_compliance_support_pins';
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'pin_hash',
|
||||
'pin_lookup',
|
||||
'expires_at',
|
||||
'revoked_at',
|
||||
'last_validated_at',
|
||||
'created_ip',
|
||||
'created_user_agent',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'expires_at' => 'datetime',
|
||||
'revoked_at' => 'datetime',
|
||||
'last_validated_at' => 'datetime',
|
||||
];
|
||||
|
||||
protected $appends = [
|
||||
'is_active',
|
||||
'is_expired',
|
||||
];
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
protected function isActive(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: fn () => !$this->is_expired && is_null($this->revoked_at),
|
||||
);
|
||||
}
|
||||
|
||||
protected function isExpired(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: fn () => $this->expires_at instanceof Carbon && $this->expires_at->isPast(),
|
||||
);
|
||||
}
|
||||
|
||||
public function scopeActive($query)
|
||||
{
|
||||
return $query
|
||||
->whereNull('revoked_at')
|
||||
->where('expires_at', '>', now());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user