/** * Export listing to CSV format. * @return Response */ public function export() { $netblocks = Netblock::all(); $columns = ['contact' => 'Contact', 'enabled' => 'Status', 'first_ip' => 'First IP', 'last_ip' => 'Last IP']; $output = '"' . implode('", "', $columns) . '"' . PHP_EOL; foreach ($netblocks as $netblock) { $row = [$netblock->contact->name . ' (' . $netblock->contact->reference . ')', ICF::inetItop($netblock['first_ip']), ICF::inetItop($netblock['last_ip']), $netblock['enabled'] ? 'Enabled' : 'Disabled']; $output .= '"' . implode('", "', $row) . '"' . PHP_EOL; } return response(substr($output, 0, -1), 200)->header('Content-Type', 'text/csv')->header('Content-Disposition', 'attachment; filename="Netblocks.csv"'); }
/** * Export listing to CSV format. * * @param string $format * @return \Illuminate\Http\Response */ public function export($format) { $netblocks = Netblock::all(); if ($format === 'csv') { $columns = ['contact' => 'Contact', 'enabled' => 'Status', 'first_ip' => 'First IP', 'last_ip' => 'Last IP']; $output = '"' . implode('", "', $columns) . '"' . PHP_EOL; foreach ($netblocks as $netblock) { $row = [$netblock->contact->name . ' (' . $netblock->contact->reference . ')', $netblock['first_ip'], $netblock['last_ip'], $netblock['enabled'] ? 'Enabled' : 'Disabled']; $output .= '"' . implode('", "', $row) . '"' . PHP_EOL; } return response(substr($output, 0, -1), 200)->header('Content-Type', 'text/csv')->header('Content-Disposition', 'attachment; filename="Netblocks.csv"'); } return Redirect::route('admin.contacts.index')->with('message', "The requested format {$format} is not available for exports"); }
/** * {@inheritdoc}. */ protected function findAll() { return Netblock::all(); }