66 lines
2 KiB
PHP
66 lines
2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Bo;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Contact;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Parsedown;
|
|
use Illuminate\Support\Facades\File;
|
|
|
|
class DashboardController extends Controller
|
|
{
|
|
/**
|
|
* Show the application dashboard.
|
|
*
|
|
* @return \Illuminate\Contracts\View\View
|
|
*/
|
|
public function index()
|
|
{
|
|
return view('bo.pages.dashboard');
|
|
}
|
|
|
|
/**
|
|
* Récupérer les contacts (fichier .csv) et les fichiers.
|
|
*
|
|
* @return \Illuminate\Http\Response|\Illuminate\Contracts\Routing\ResponseFactory
|
|
*/
|
|
public function exportContact()
|
|
{
|
|
$csv_file = 'export-contacts.csv';
|
|
$csvExporter = new \Laracsv\Export();
|
|
$contacts = Contact::all();
|
|
|
|
$csvExporter->beforeEach(function ($contact) {
|
|
$contact->app_user_id = $contact->firstname . " " . $contact->lastname;
|
|
$contact->phone = "$contact->phone";
|
|
});
|
|
|
|
$csvExporter->getWriter()->setDelimiter(';');
|
|
$csvExporter->getWriter()->setEnclosure('"');
|
|
$csvExporter->getWriter()->setOutputBOM(\League\Csv\Reader::BOM_UTF8);
|
|
$csvExporter->build($contacts, [
|
|
'app_user_id' => 'Propriétaire',
|
|
'email' => 'Email',
|
|
'type' => 'Type du contact',
|
|
'other' => 'Type autre',
|
|
'select1' => 'Select n°1',
|
|
'select2' => 'Select n°2',
|
|
'name' => 'Nom',
|
|
'firstname' => 'Prénom',
|
|
'company' => 'Entreprise',
|
|
'address' => 'Adresse',
|
|
'phone' => 'Téléphone',
|
|
'notes' => 'Notes',
|
|
'visits' => 'Visites',
|
|
]);
|
|
|
|
Storage::disk('public')->put($csv_file, $csvExporter->getWriter()->getContent());
|
|
|
|
return response()->download(
|
|
storage_path('app/public/') . "$csv_file",
|
|
'contacts.csv',
|
|
['Content-Type' => 'text/csv; charset=utf-8']
|
|
)->deleteFileAfterSend();
|
|
}
|
|
}
|