Nuevos cambios hechos de diseño
This commit is contained in:
65
desarrollo2/app/Models/ProductsExport.php
Normal file
65
desarrollo2/app/Models/ProductsExport.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Product;
|
||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||
use Maatwebsite\Excel\Concerns\FromQuery;
|
||||
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
|
||||
class ProductsExport implements FromCollection, WithMapping, WithHeadings
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
return Product::all();
|
||||
}
|
||||
|
||||
public function headings(): array
|
||||
{
|
||||
return [
|
||||
'name',
|
||||
'description',
|
||||
'added_by',
|
||||
'user_id',
|
||||
'category_id',
|
||||
'brand_id',
|
||||
'video_provider',
|
||||
'video_link',
|
||||
'unit_price',
|
||||
'purchase_price',
|
||||
'unit',
|
||||
'current_stock',
|
||||
'meta_title',
|
||||
'meta_description',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @var Product $product
|
||||
*/
|
||||
public function map($product): array
|
||||
{
|
||||
$qty = 0;
|
||||
foreach ($product->stocks as $key => $stock) {
|
||||
$qty += $stock->qty;
|
||||
}
|
||||
return [
|
||||
$product->name,
|
||||
$product->description,
|
||||
$product->added_by,
|
||||
$product->user_id,
|
||||
$product->category_id,
|
||||
$product->brand_id,
|
||||
$product->video_provider,
|
||||
$product->video_link,
|
||||
$product->unit_price,
|
||||
$product->purchase_price,
|
||||
$product->unit,
|
||||
// $product->current_stock,
|
||||
$qty,
|
||||
$product->meta_title,
|
||||
$product->meta_description,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user