Exporting
On the export page you can do some XLS or CSV exports from the database. There are 3 types of exports you can do - model, e-mail export of all users and custom (which is really your own custom export function). You can add new export cases in the exportables array in config/hotcoffee.php.
Say you want to export all the products.
1
'exportables' => [
2
3
'App\Products' => [ // Model name
4
'name' => 'Export products', // Text for the <option> in the <select> field
5
'type' => 'model', // Type (if you want to export a whole table (or all models) type should be "model"
6
'fields' => ['name', 'email', 'created_at'], // Which fields to export
7
'file_name' => 'user_list', // Name of exported file
8
'file_type' => 'xls', // File type (xls or csv)
9
],
10
11
],
Copied!
Sometimes you may need to alter the collection before exporting. You can use the type custom to create your own custom export case.
1
'exportables' => [
2
3
'custom_case' => [
4
'name' => 'custom', // Text for the <option> in the <select> field
5
'type' => 'custom', // Type
6
'case' => 'my_custom_export', // Case
7
'file_name' => 'custom', // Name for exported file
8
'file_type' => 'xls', // File type (xls or csv)
9
],
10
11
],
Copied!
Next open app\Http\Controllers\Admin\CustomExportController.php and add your case in the collection() method:
1
public function collection() {
2
switch ($this->export) {
3
4
case 'my_custom_export':
5
// Your code here
6
return Product::select('id', 'name', 'price')->get();
7
break;
8
}
9
}
Copied!
Exporting is possible thanks to the Maatwebsite/Laravel-Excel. You can find the full documentation here.
Last modified 1yr ago
Copy link