From ef446ef862b07217388522ae793ffa2ae7c4e48f Mon Sep 17 00:00:00 2001 From: Yoga Pangestu Date: Tue, 27 Jan 2026 21:32:24 +0700 Subject: [PATCH] feat: Change Company partnerMedia relationship to HasOne and enhance PartnerResource company description display. --- .../Resources/Manage/Partners/PartnerResource.php | 11 +++++++++-- app/Models/Company.php | 5 +++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/Filament/Resources/Manage/Partners/PartnerResource.php b/app/Filament/Resources/Manage/Partners/PartnerResource.php index 9000a61..7c7e31f 100644 --- a/app/Filament/Resources/Manage/Partners/PartnerResource.php +++ b/app/Filament/Resources/Manage/Partners/PartnerResource.php @@ -20,6 +20,8 @@ use Filament\Tables\Filters\TrashedFilter; use Filament\Tables\Table; use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\HtmlString; use Joaopaulolndev\FilamentPdfViewer\Infolists\Components\PdfViewerEntry; use UnitEnum; @@ -278,7 +280,12 @@ public static function table(Table $table): Table ->label('Perusahaan') ->searchable() ->sortable() - ->description(fn (User $record): string => 'Direktur: '.$record->company?->director_name), + ->description( + fn (User $record) => new HtmlString( + 'Akun: '.$record->name. + '
Direktur: '.$record->company?->director_name + ) + ), TextColumn::make('company.partnerMedia.name') ->label('Media') @@ -342,7 +349,7 @@ private static function fileEntry( ): PdfViewerEntry { return PdfViewerEntry::make($name) ->hiddenLabel() - ->getStateUsing(function (\Illuminate\Database\Eloquent\Model $record) use ($name, $mediaOwner, $collection): ?string { + ->getStateUsing(function (Model $record) use ($name, $mediaOwner, $collection): ?string { $owner = data_get($record, $mediaOwner); if (! $owner) { diff --git a/app/Models/Company.php b/app/Models/Company.php index 341b100..8221b81 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -8,6 +8,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasManyThrough; +use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\SoftDeletes; use Spatie\MediaLibrary\HasMedia; use Spatie\MediaLibrary\InteractsWithMedia; @@ -31,9 +32,9 @@ public function journalists(): HasManyThrough return $this->hasManyThrough(Journalist::class, PartnerMedia::class); } - public function partnerMedias(): HasMany + public function partnerMedia(): HasOne { - return $this->hasMany(PartnerMedia::class); + return $this->hasOne(PartnerMedia::class); } public function user(): BelongsTo