/** * Export listing to CSV format. * * @param string $format * * @return \Illuminate\Http\Response */ public function export($format) { $auth_account = $this->auth_user->account; if ($auth_account->isSystemAccount()) { $contacts = Contact::all(); } else { $contacts = Contact::select('contacts.*')->leftJoin('accounts', 'accounts.id', '=', 'contacts.account_id')->where('accounts.id', '=', $auth_account->id); } if ($format === 'csv') { $columns = ['reference' => 'Reference', 'contact' => 'name', 'enabled' => 'Status', 'email' => 'E-Mail address', 'api_host' => 'RPC address', 'auto_notify' => 'Notifications']; $output = '"' . implode('", "', $columns) . '"' . PHP_EOL; foreach ($contacts as $contact) { $row = [$contact->reference, $contact->name, $contact['enabled'] ? 'Enabled' : 'Disabled', $contact['email'], $contact['api_host'], $contact['auto_notify'] ? 'Automatic' : 'Manual']; $output .= '"' . implode('", "', $row) . '"' . PHP_EOL; } return response(substr($output, 0, -1), 200)->header('Content-Type', 'text/csv')->header('Content-Disposition', 'attachment; filename="Contacts.csv"'); } return Redirect::route('admin.contacts.index')->with('message', "The requested format {$format} is not available for exports"); }
/** * Show the form for editing the specified resource. * * @param Netblock $netblock * * @return \Illuminate\Http\Response */ public function edit(Netblock $netblock) { $auth_account = $this->auth_user->account; if (!$auth_account->isSystemAccount()) { $contacts = Contact::select('contacts.*')->where('account_id', $auth_account->id)->get()->lists('name', 'id'); } else { $contacts = Contact::lists('name', 'id'); } return view('netblocks.edit')->with('netblock', $netblock)->with('contact_selection', $contacts)->with('selected', $netblock->contact_id)->with('auth_user', $this->auth_user); }