# Interact with exports
# Asking the user for a filename
If you want your users to choose their own filename when exporting a resource, you can use the askForFilename()
interaction.
/**
* Get the actions available for the resource.
*
* @param \Illuminate\Http\Request $request
*
* @return array
*/
public function actions(Request $request)
{
return [
(new DownloadExcel())->askForFilename()
];
}
2
3
4
5
6
7
8
9
10
11
12
13
The user will now be prompted with the question how he wants to name the file.
💡 If you want to have a custom label, you can simply pass that via the method: (new DownloadExcel())->askForFilename(__('Filename for your export'))
When not specifying any default writer type, the user can control the file type by typing an extensions in the filename.
E.g. users.csv
will result into a CSV document. If the user doesn't specify any extension, it will default to .xlsx
.
If you don't want the user to have this kind of control,make sure to use withWriterType()
.
# Asking the user for the writer type
If you want your users to choose their own writer type when exporting a resource, you can use the askForWriterType()
interaction.
/**
* Get the actions available for the resource.
*
* @param \Illuminate\Http\Request $request
*
* @return array
*/
public function actions(Request $request)
{
return [
(new DownloadExcel())->askForWriterType()
];
}
2
3
4
5
6
7
8
9
10
11
12
13
💡 If you want to specify the options the user can choose yourself, you can pass them via the askForWriterType
:
/**
* Get the actions available for the resource.
*
* @param \Illuminate\Http\Request $request
*
* @return array
*/
public function actions(Request $request)
{
return [
(new DownloadExcel)->askForWriterType([
\Maatwebsite\Excel\Excel::CSV => __('Csv document'),
]),
];
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
💡 If you want to have a custom label, you can simply pass that via the method: (new DownloadExcel())->askForWriterType(null, __('Filename for your export'))