xxxxxxxxxx
Its required maatwebsite/excel package
Deatils tutorial in our bolg:
xxxxxxxxxx
use Illuminate\Support\Facades\Response;
use App\Product;
public function export()
{
$products = Product::all();
$csvFileName = 'products.csv';
$headers = [
'Content-Type' => 'text/csv',
'Content-Disposition' => 'attachment; filename="' . $csvFileName . '"',
];
$handle = fopen('php://output', 'w');
fputcsv($handle, ['Name', 'Price']); // Add more headers as needed
foreach ($products as $product) {
fputcsv($handle, [$product->name, $product->price]); // Add more fields as needed
}
fclose($handle);
return Response::make('', 200, $headers);
}
xxxxxxxxxx
function csvToArray($filename = '', $delimiter = ',')
{
if (!file_exists($filename) || !is_readable($filename))
return false;
$header = null;
$data = array();
if (($handle = fopen($filename, 'r')) !== false)
{
while (($row = fgetcsv($handle, 1000, $delimiter)) !== false)
{
if (!$header)
$header = $row;
else
$data[] = array_combine($header, $row);
}
fclose($handle);
}
return $data;
}
xxxxxxxxxx
use Illuminate\Support\Facades\Response;
use App\Product;
public function export()
{
$products = Product::all();
$csvFileName = 'products.csv';
$headers = [
'Content-Type' => 'text/csv',
'Content-Disposition' => 'attachment; filename="' . $csvFileName . '"',
];
$handle = fopen('php://output', 'w');
fputcsv($handle, ['Name', 'Price']); // Add more headers as needed
foreach ($products as $product) {
fputcsv($handle, [$product->name, $product->price]); // Add more fields as needed
}
fclose($handle);
return Response::make('', 200, $headers);
}
xxxxxxxxxx
Its required maatwebsite/excel package
Deatils tutorial in our bolg:
xxxxxxxxxx
Its required maatwebsite/excel package
Deatils tutorial in our bolg:
xxxxxxxxxx
Its required maatwebsite/excel package
Deatils tutorial in our bolg:
xxxxxxxxxx
Its required maatwebsite/excel package
Deatils tutorial in our bolg:
xxxxxxxxxx
Its required maatwebsite/excel package
Deatils tutorial in our bolg:
xxxxxxxxxx
Its required maatwebsite/excel package
Deatils tutorial in our bolg: