feat: Refactor media handling and improve file upload configurations in Cooperation and Journalist resources
This commit is contained in:
parent
b97b8a3708
commit
6265410fb0
@ -136,9 +136,9 @@ public static function infolist(Schema $schema): Schema
|
||||
|
||||
ImageEntry::make('banner')
|
||||
->label('Banner')
|
||||
->getStateUsing(fn ($record) => optional($record->getMedia('banners')->sortByDesc('created_at')->first())->getPathRelativeToRoot())
|
||||
->getStateUsing(fn ($record) => optional($record->getMedia('cooperations')->where('custom_properties.doc_type', 'banner')->sortByDesc('created_at')->first())->getPathRelativeToRoot())
|
||||
->disk(config('filesystems.default'))
|
||||
->visible(fn ($record) => $record->getMedia('banners')->isNotEmpty()),
|
||||
->visible(fn ($record) => $record->getMedia('cooperations')->isNotEmpty()),
|
||||
]),
|
||||
|
||||
TextEntry::make('description')
|
||||
|
||||
@ -39,6 +39,7 @@ protected function afterCreate(): void
|
||||
}
|
||||
|
||||
$filePath = collect($data['proposal_template'])->first();
|
||||
dd($filePath);
|
||||
|
||||
$fullPath = Storage::disk(config('filesystems.default'))->path($filePath);
|
||||
|
||||
|
||||
@ -69,8 +69,8 @@ protected function afterSave(): void
|
||||
->preservingOriginal()
|
||||
->withCustomProperties([
|
||||
'feature' => 'cooperations',
|
||||
'date' => now()->toDateString(),
|
||||
'doc_type' => 'proposal-template',
|
||||
'date' => now()->toDateString(),
|
||||
])
|
||||
->toMediaCollection('cooperations');
|
||||
}
|
||||
|
||||
@ -84,7 +84,12 @@ public static function configure(Schema $schema): Schema
|
||||
->disk(config('filesystems.default'))
|
||||
->acceptedFileTypes(['image/*'])
|
||||
->maxSize(1024 * 3)
|
||||
->collection('banners')
|
||||
->collection('cooperations')
|
||||
->customProperties(fn () => [
|
||||
'feature' => 'cooperations',
|
||||
'doc_type' => 'banner',
|
||||
'date' => now()->toDateString(),
|
||||
])
|
||||
->image(),
|
||||
|
||||
AdvancedFileUpload::make('proposal_template')
|
||||
@ -92,7 +97,7 @@ public static function configure(Schema $schema): Schema
|
||||
->disk(config('filesystems.default'))
|
||||
->acceptedFileTypes(['application/pdf'])
|
||||
->maxSize(1024 * 10)
|
||||
->directory('cooperations/templates/'.now()->toDateString())
|
||||
->directory(fn () => 'cooperations/proposal-template/'.now()->toDateString())
|
||||
->required(),
|
||||
]),
|
||||
])
|
||||
|
||||
@ -90,9 +90,9 @@ public static function configure(Table $table): Table
|
||||
->html()
|
||||
->getStateUsing(function (Cooperation $record) {
|
||||
$record->loadCount([
|
||||
'partnerMedia as approved_count' => fn ($query) => $query->where('cooperations.status', ApprovalStatus::ACCEPTED),
|
||||
'partnerMedia as rejected_count' => fn ($query) => $query->where('cooperations.status', ApprovalStatus::REJECTED),
|
||||
'partnerMedia as pending_count' => fn ($query) => $query->where('cooperations.status', ApprovalStatus::PENDING),
|
||||
'partnerMedia as approved_count' => fn ($query) => $query->where('cooperation_media.status', ApprovalStatus::ACCEPTED),
|
||||
'partnerMedia as rejected_count' => fn ($query) => $query->where('cooperation_media.status', ApprovalStatus::REJECTED),
|
||||
'partnerMedia as pending_count' => fn ($query) => $query->where('cooperation_media.status', ApprovalStatus::PENDING),
|
||||
]);
|
||||
|
||||
$totalCount = $record->partnerMedia()->count();
|
||||
@ -241,18 +241,18 @@ public static function configure(Table $table): Table
|
||||
->url(),
|
||||
|
||||
Textarea::make('description')
|
||||
->label('Deskripsi Proposal')
|
||||
->label('Deskripsi')
|
||||
->autocomplete(false)
|
||||
->required()
|
||||
->rows(4)
|
||||
->placeholder('...'),
|
||||
|
||||
AdvancedFileUpload::make('proposal_attachment')
|
||||
->label('Lampiran Proposal')
|
||||
->label('Lampiran')
|
||||
->disk(config('filesystems.default'))
|
||||
->acceptedFileTypes(['application/pdf'])
|
||||
->maxSize(1024 * 10)
|
||||
->directory('cooperation/proposal/'.now()->toDateString())
|
||||
->directory(fn () => 'cooperations/proposal-attachment/'.now()->toDateString())
|
||||
->required(),
|
||||
])
|
||||
->action(function ($record, array $data) {
|
||||
|
||||
@ -60,7 +60,7 @@ public static function form(Schema $schema): Schema
|
||||
'max_size' => 1024 * 10,
|
||||
'file_name' => 'press_card_docs',
|
||||
'accept' => ['application/pdf'],
|
||||
'folder' => 'journalists/press-card/',
|
||||
'folder' => 'press-card/',
|
||||
],
|
||||
[
|
||||
'title' => 'Sertifikat UKW',
|
||||
@ -70,7 +70,7 @@ public static function form(Schema $schema): Schema
|
||||
'max_size' => 1024 * 10,
|
||||
'file_name' => 'ukw_certificate_docs',
|
||||
'accept' => ['application/pdf'],
|
||||
'folder' => 'journalists/ukw-certificate/',
|
||||
'folder' => 'ukw-certificate/',
|
||||
],
|
||||
];
|
||||
|
||||
@ -119,6 +119,7 @@ public static function form(Schema $schema): Schema
|
||||
->hiddenLabel()
|
||||
->disk(config('filesystems.default'))
|
||||
->acceptedFileTypes($doc['accept'])
|
||||
->directory(fn () => 'journalists/'.$doc['folder'].now()->toDateString())
|
||||
->maxSize($doc['max_size'])
|
||||
->required(),
|
||||
])
|
||||
|
||||
@ -82,6 +82,10 @@ public static function configure(Schema $schema): Schema
|
||||
->acceptedFileTypes(['image/*'])
|
||||
->maxSize(1024 * 3)
|
||||
->collection('content-recpaps')
|
||||
->customProperties(fn () => [
|
||||
'feature' => 'content-recaps',
|
||||
'date' => now()->toDateString(),
|
||||
])
|
||||
->image()
|
||||
->required(),
|
||||
]),
|
||||
|
||||
@ -24,6 +24,11 @@ protected function getHeaderActions(): array
|
||||
];
|
||||
}
|
||||
|
||||
protected function getRedirectUrl(): string
|
||||
{
|
||||
return $this->getResource()::getUrl('index');
|
||||
}
|
||||
|
||||
protected function mutateFormDataBeforeCreate(array $data): array
|
||||
{
|
||||
$latestCode = MediaMonitoring::max('code');
|
||||
|
||||
@ -113,6 +113,10 @@ public static function configure(Schema $schema): Schema
|
||||
->acceptedFileTypes(['image/*'])
|
||||
->maxSize(1024 * 3)
|
||||
->collection('media-monitorings')
|
||||
->customProperties(fn () => [
|
||||
'feature' => 'media-monitorings',
|
||||
'date' => now()->toDateString(),
|
||||
])
|
||||
->image()
|
||||
->required(),
|
||||
]),
|
||||
|
||||
@ -96,6 +96,10 @@ public static function configure(Schema $schema): Schema
|
||||
->acceptedFileTypes(['image/*'])
|
||||
->maxSize(1024 * 3)
|
||||
->collection('news')
|
||||
->customProperties(fn () => [
|
||||
'feature' => 'news',
|
||||
'date' => now()->toDateString(),
|
||||
])
|
||||
->image()
|
||||
->required(),
|
||||
]),
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Spatie\MediaLibrary\HasMedia;
|
||||
use Spatie\MediaLibrary\InteractsWithMedia;
|
||||
@ -52,7 +53,7 @@ public function partnerMedia(): BelongsToMany
|
||||
->withTimestamps();
|
||||
}
|
||||
|
||||
public function reports(): \Illuminate\Database\Eloquent\Relations\HasManyThrough
|
||||
public function reports(): HasManyThrough
|
||||
{
|
||||
return $this->hasManyThrough(Report::class, TaskAssignment::class);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user