protected function getFormSchema(): array
{
$currentTenantId = Filament::getTenant()->id;
$UserMatchList = \App\Models\Goods\Case\UserMatchList::query()
->where('cabinet_id', $currentTenantId)
->get()
->map(function ($item) {
return $item->vendor_code;
})
->toArray();
$component = Components\FileUpload::make('attachments')
->hiddenLabel()
->directory("cases/{$currentTenantId}")
->acceptedFileTypes(['image/jpeg'])
->multiple()
->preserveFilenames()
->fetchFileInformation(false)
->moveFiles(true)
->panelLayout('grid')
->afterStateUpdated(function (Set $set, Components\FileUpload $component, $state, $livewire) use ($UserMatchList) {
/** @var \Livewire\Features\SupportFileUploads\TemporaryUploadedFile $file */
foreach ($state as $file) {
$path = $file->getRealPath();
$fileName = pathinfo($path, PATHINFO_FILENAME);
if (!in_array($fileName, $UserMatchList)) {
Notification::make()
->title('Filename Error')
->danger()
->send();
$file->delete();// Dont work
return;
}
}
});
return [
Components\Fieldset::make('cases')
->schema([$component])
];
}