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.

'exportables' => [
'App\Products' => [ // Model name
'name' => 'Export products', // Text for the <option> in the <select> field
'type' => 'model', // Type (if you want to export a whole table (or all models) type should be "model"
'fields' => ['name', 'email', 'created_at'], // Which fields to export
'file_name' => 'user_list', // Name of exported file
'file_type' => 'xls', // File type (xls or csv)
],
],

Sometimes you may need to alter the collection before exporting. You can use the type custom to create your own custom export case.

'exportables' => [
'custom_case' => [
'name' => 'custom', // Text for the <option> in the <select> field
'type' => 'custom', // Type
'case' => 'my_custom_export', // Case
'file_name' => 'custom', // Name for exported file
'file_type' => 'xls', // File type (xls or csv)
],
],

Next open app\Http\Controllers\Admin\CustomExportController.php and add your case in the collection() method:

public function collection() {
switch ($this->export) {
case 'my_custom_export':
// Your code here
return Product::select('id', 'name', 'price')->get();
break;
}
}

Exporting is possible thanks to the Maatwebsite/Laravel-Excel. You can find the full documentation here.