42 lines
1.3 KiB
PHP
42 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Domains\Integration\Models;
|
|
|
|
use App\Domains\Integration\Casts\EncryptedIntegrationData;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
class IntegrationInstance extends Model
|
|
{
|
|
// The ciphertext changes whenever credentials are saved, so old tokens cannot be reused.
|
|
public function tokenCacheKey(): string
|
|
{
|
|
return 'integration_token:instance:'.$this->id.':'.hash('sha256', (string) $this->getRawOriginal('integration_data'));
|
|
}
|
|
|
|
protected $fillable = ['integration_code', 'name', 'integration_data'];
|
|
|
|
protected $hidden = ['integration_data'];
|
|
|
|
protected $casts = ['integration_data' => EncryptedIntegrationData::class];
|
|
|
|
/** @return BelongsTo<Integration, $this> */
|
|
public function integration(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Integration::class, 'integration_code', 'integration_code');
|
|
}
|
|
|
|
/** @return HasMany<ClientIntegration, $this> */
|
|
public function clientIntegrations(): HasMany
|
|
{
|
|
return $this->hasMany(ClientIntegration::class);
|
|
}
|
|
|
|
/** @return HasMany<WebsiteTypeIntegration, $this> */
|
|
public function websiteTypeIntegrations(): HasMany
|
|
{
|
|
return $this->hasMany(WebsiteTypeIntegration::class);
|
|
}
|
|
}
|