You are doing many things, and all are named the same..
try this:
return Excel::download(new ProductsExport([
[1, 2, 3],
[4, 5, 6]
]), 'products.xlsx');
I want to export Products by tag. when I do dd($products). Its giving me correct array. But the downloaded file is empty.
My controller:
public function export(Request $request) {
$tag = Tag::where('id', $request->selectTag)->get()->first();
$products = new ProductsExport([
[1, 2, 3],
[4, 5, 6]
]);
$products = $tag->products()->get();
//dd($products);
return Excel::download($products, 'products.xlsx');
}
ProductsExport.php
protected $products;
public function __construct(array $products)
{
$this->products = $products;
}
public function array(): array
{
return $this->products;
}
/**
* @return \Illuminate\Support\Collection
*/
public function collection()
{
$products = Product::select(
'name', 'code', 'price', 'slug', 'details', 'ecommerce', 'quantity',
'description', 'created_at', 'category_id', 'origin', 'warranty')->get();
// $category = $products->tags;
return $products;
}
You are doing many things, and all are named the same..
try this:
return Excel::download(new ProductsExport([
[1, 2, 3],
[4, 5, 6]
]), 'products.xlsx');
Please or to participate in this conversation.