F
Filament16mo ago
Samer

how to pass uploaded file to Laravel Excel to load the content into array or repeater

Hi , im having an action on table header to bulk upload from an Excel sheet, I'm trying to pass the uploaded file to Laravel Excel to get the content then i'll pass that array to form, I'm trying to pass the attachment to $array = Excel::toArray(new UsersImport, 'users.xlsx'); , So i was trying to do something like $array = Excel::toArray(new ChartOfAccountImport($this->record), $this->record->attachement); so basically I want to know how to pass the file and which place to put that logic like is there is something like afterStep or AfterUpload event
->headerActions([
Action::make('Bulk Upload')->icon('heroicon-m-arrow-up-tray')

->iconPosition(IconPosition::After)

->steps([
Step::make('File Upload')
->description('Upload the Data File here')
->schema([
FileUpload::make('attachment')

])
->columns(1)

,
Step::make('Read file and Populate ')
->description('Check and Validation Data')
->schema([
Repeater::make('Accounts')
->schema([
TextInput::make('code')
->required()
->inlineLabel()

->maxLength(15),
TextInput::make('name')
->required()
->maxLength(100)
->inlineLabel(),
TextInput::make('shortname')

->maxLength(15)
->inlineLabel(),
])
->defaultItems(3)
->columns(3)

]),
Step::make('View Results')
->description('View the Results')
->schema([

]),
])
->headerActions([
Action::make('Bulk Upload')->icon('heroicon-m-arrow-up-tray')

->iconPosition(IconPosition::After)

->steps([
Step::make('File Upload')
->description('Upload the Data File here')
->schema([
FileUpload::make('attachment')

])
->columns(1)

,
Step::make('Read file and Populate ')
->description('Check and Validation Data')
->schema([
Repeater::make('Accounts')
->schema([
TextInput::make('code')
->required()
->inlineLabel()

->maxLength(15),
TextInput::make('name')
->required()
->maxLength(100)
->inlineLabel(),
TextInput::make('shortname')

->maxLength(15)
->inlineLabel(),
])
->defaultItems(3)
->columns(3)

]),
Step::make('View Results')
->description('View the Results')
->schema([

]),
])
1 Reply
Samer
SamerOP16mo ago
Manage to get the Excel rows by the following, its not create but it working
FileUpload::make('attachment')

->afterStateUpdated(function (callable $set, TemporaryUploadedFile $state) {


$Accounts = Excel::toArray(new ChartOfAccountImport(), $state);
dd($Accounts);
}),
FileUpload::make('attachment')

->afterStateUpdated(function (callable $set, TemporaryUploadedFile $state) {


$Accounts = Excel::toArray(new ChartOfAccountImport(), $state);
dd($Accounts);
}),
` Thanks @steen.rabol old message,
Want results from more Discord servers?
Add your server