Files
freeu-project/app/Exports/CompanyExport.php
Ritikesh yadav c661166e1d first commit
2024-03-28 14:52:40 +05:30

107 lines
2.9 KiB
PHP

<?php
namespace App\Exports;
use App\Models\Company;
use Maatwebsite\Excel\Concerns\FromCollection;
//frow laravel excel drawing(image export)
use Maatwebsite\Excel\Concerns\WithDrawings;
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithColumnWidths;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\DB;
use Maatwebsite\Excel\Concerns\FromView;
// class CompanyExport implements FromCollection, WithHeadings, WithColumnWidths, WithDrawings
class CompanyExport implements FromView
{
/**
* @return \Illuminate\Support\Collection
*/
protected $query;
public function __construct($query)
{
$this->query = $query;
}
public function view(): View
{
$companies = DB::table('companies');
// $companies->where('some_field', 'some_value');
// Conditionally add another where
// if($this->query['search']){
// dd('exists');
// }else{
// dd('does not exists');
// }
// if ($this->query['search']) $companies->where('company_name', 'like', '%' . $this->query['search'] . '%');
// // if ($this->query['search']) $companies->where('company_name', $this->query['search']);
// if($this->query['status'] !=='orderby') $companies->where('status',$this->query['status']);
// if($this->query['status']=== 'orderby') $companies->orderBy('id','desc');
if($this->query['status'] == 'orderby'){
$companies->orderBy('id','desc');
}else if($this->query['status']){
$companies->where('status',$this->query['status']);
}
$companies->where('company_name', 'like', '%' . $this->query['search'] . '%');
$companies = $companies->get();
// dd($this->query);
// dd($companies);
// return 'hello world';
return view('report.excel', [
'companies' => $companies
]);
}
// public function collection()
// {
// return Company::all();
// }
// public function drawings()
// {
// $no = 3;
// $drawing = new Drawing();
// $drawing->setName('company_logo');
// $drawing->setDescription('This is company logo');
// $drawing->setPath(public_path('uploads\manufactures_company\logo\1683634879.png'));
// $drawing->setHeight(90);
// $drawing->setCoordinates("C$no");
// return $drawing;
// }
// public function headings(): array
// {
// return [
// 'id',
// 'company_name',
// 'company_logo',
// 'created_at'
// ];
// }
// public function columnWidths(): array
// {
// return [
// 'A' => 30,
// 'B' => 30,
// 'C' => 30,
// 'D' => 30,
// ];
// }
}