ldc-com-app-bo/app/Http/Controllers/Bo/DashboardController.php

67 lines
2 KiB
PHP
Raw Normal View History

2023-03-14 14:57:03 +01:00
<?php
namespace App\Http\Controllers\Bo;
use App\Http\Controllers\Controller;
2023-07-13 08:34:54 +00:00
use App\Models\Contact;
use Illuminate\Support\Facades\Storage;
use Parsedown;
use Illuminate\Support\Facades\File;
2023-03-14 14:57:03 +01:00
class DashboardController extends Controller
{
/**
2023-07-13 08:34:54 +00:00
* Show the application dashboard.
2023-03-14 14:57:03 +01:00
*
* @return \Illuminate\Contracts\View\View
*/
public function index()
{
return view('bo.pages.dashboard');
}
2023-07-13 08:34:54 +00:00
/**
* 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();
}
2023-03-14 14:57:03 +01:00
}