mardi 30 mars 2021

php laravel excel two parameter not accept ? why

PhpOffice\PhpSpreadsheet\Writer\Exception: No writer found for type 1 in file C:\xampp\htdocs\api_product_catelog\vendor\phpoffice\phpspreadsheet\src\PhpSpreadsheet\IOFactory.php on line 47 $this->company $this->catogory value both together then not given in output! request in get sucess fully value both company id or catagery id but query not working for get it's work only for company id

the total code is there

<?php

namespace App\Exports;

use App\Models\Product;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\FromQuery;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithStrictNullComparison;
use PhpOffice\PhpSpreadsheet\IOFactory;



class ProductsExport implements  FromQuery, WithHeadings, ShouldAutoSize ,WithStrictNullComparison
{
    /**
    * @return \Illuminate\Support\Collection
    */
     use Exportable;

    public function forCompany(int $comapny)
    {
        $this->company = $comapny;
        
        return $this;
    }
    public function forCategory(int $category)
    {
        $this->category = $category;
        
        return $this;
    }
    
public function headings(): array
    {
        return [
            'id',
            'product_name',
            'category_id',
            'brand_id',
            'product_hsn_sac',
            'search_keyword',
            'price',
            'sale',
            'new',
            'offer_price',
            'gst_percentage',
            'detail',
            'advantages',
            'characteristics',
            'specification',
            'additional_info',
            'description',
        ];
    }
     public function query($requestData = null) {
        // var_dump($requestData);die();
        if ($this->category != 0) {
            $product = Product::select('id', 'product_name', 'category_id',  'brand_id', 'product_hsn_sac', 'search_keyword', 'price', 'sale', 'new','offer_price', 'gst_percentage',  'detail', 'advantages', 'characteristics', 'specification', 'additional_info','description')
               ->where('company_id',$this->company)
               ->where('category_id', $this->category);
        }else {
             $product = Product::select('id', 'product_name', 'category_id',  'brand_id', 'product_hsn_sac', 'search_keyword', 'price', 'sale', 'new','offer_price', 'gst_percentage',  'detail', 'advantages', 'characteristics', 'specification', 'additional_info','description')
                ->where('company_id',$this->company);
        }


    return $product;
    }

    public function map($product): array
    {
        return [
            $product->id,
            $product->product_name,
            $product->category_id,
            $product->brand_id,
            $product->product_hsn_sac,
            $product->search_keyword,
            $product->price,
            $product->sale,
            $product->new,
            $product->offer_price,
            $product->gst_percentage,
            $product->detail,
            $product->advantages,
            $product->characteristics,
            $product->specification,
            $product->additional_info,
            $product->description,
        ];
    }

    
}


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire