- Added comprehensive documentation for `ConnectionProviderService`, outlining architectural design, coding standards, and operational flows. - Enhanced `ConnectionProvider` and `ConnectedApp` models with Spatie activity logging configuration for detailed CRUD activity tracking. - Updated delete methods in service classes to include audit logs and cascade behavior refinement. - Revised activity log migration schema for stricter typing and method structure.
51 lines
1.5 KiB
PHP
51 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
use Illuminate\Database\Eloquent\{Model, Relations\BelongsTo, SoftDeletes};
|
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
|
use Spatie\Activitylog\Models\Concerns\LogsActivity;
|
|
use Spatie\Activitylog\Support\LogOptions;
|
|
|
|
#[Fillable([
|
|
'name',
|
|
'slug',
|
|
'connection_protocol_id',
|
|
'connection_provider_id',
|
|
'connection_status_id',
|
|
])]
|
|
class ConnectedApp extends Model
|
|
{
|
|
use LogsActivity, SoftDeletes;
|
|
|
|
public function protocol(): HasOne
|
|
{
|
|
return $this->hasOne(ConnectionProtocol::class, 'id', 'connection_protocol_id');
|
|
}
|
|
|
|
public function provider(): BelongsTo
|
|
{
|
|
return $this->belongsTo(ConnectionProvider::class, 'connection_provider_id');
|
|
}
|
|
|
|
public function status(): HasOne
|
|
{
|
|
return $this->hasOne(ConnectionStatus::class, 'id', 'connection_status_id');
|
|
}
|
|
|
|
public function getActivitylogOptions(): LogOptions
|
|
{
|
|
return LogOptions::defaults()
|
|
->logFillable() // Log all fillable attributes
|
|
->logOnlyDirty() // Log only attributes that actually changed
|
|
->dontLogIfAttributesChangedOnly(['updated_at']) // Skip if only updated_at changed
|
|
->dontLogEmptyChanges() // Prevent saving logs with no changed attributes
|
|
->setDescriptionForEvent(fn (
|
|
string $eventName
|
|
) => ":causer.name {$eventName} connected app ':subject.name'");
|
|
}
|
|
}
|