63 lines
2.3 KiB
PHP
63 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Exports;
|
|
|
|
use App\Models\Admin\monthly_update_master;
|
|
use App\Models\AlternativeInvestmentFund;
|
|
use App\Models\FractionalRealEstate;
|
|
use App\Models\MonthlyUpdateMaster;
|
|
use App\Models\Product;
|
|
use Maatwebsite\Excel\Concerns\Exportable;
|
|
use Maatwebsite\Excel\Concerns\FromCollection;
|
|
use Maatwebsite\Excel\Concerns\WithHeadings;
|
|
|
|
class UserProduct implements FromCollection, WithHeadings
|
|
{
|
|
// use Exportable;
|
|
/**
|
|
* @return \Illuminate\Support\Collection
|
|
*/
|
|
|
|
protected $category;
|
|
protected $columns;
|
|
function __construct($category,$columns)
|
|
{
|
|
$this->category = $category;
|
|
$this->columns = $columns;
|
|
}
|
|
public function collection()
|
|
{
|
|
$products_detail = MonthlyUpdateMaster::with('investor')->whereIn('categories',$this->category)->where('holding_status','Holding')->get();
|
|
$return_data = [];
|
|
$data = collect();
|
|
$products_detail->each(function ($value) use ($data){
|
|
// dd($value);
|
|
$return_data['name'] = $value->investor->name;
|
|
$return_data['email'] = $value->investor->email;
|
|
$return_data['custom_id'] = $value->custom_id;
|
|
$return_data['product_name'] = $value->product_name;
|
|
$return_data['product_category'] = $value->product_category;
|
|
// if(AlternativeInvestmentFund::where('id',$value->products_id)->exists())
|
|
// {
|
|
// $aid_data = Product::with('alternativeInvestmentFund','category')->where('id',$value->products_id)->first();
|
|
// $return_data['product_name'] = $aid_data->alternativeInvestmentFund->fund_name;
|
|
// $return_data['product_category'] = $aid_data->category->category_name;
|
|
// }
|
|
// if(FractionalRealEstate::where('id',$value->products_id)->exists())
|
|
// {
|
|
// $aid_data = Product::with('fractional_real_estate','category')->where('id',$value->products_id)->first();
|
|
// $return_data['product_name'] = $aid_data->fractional_real_estate->property_name_and_location;
|
|
// $return_data['product_category'] = $aid_data->category->category_name;
|
|
// }
|
|
|
|
$data->push($return_data);
|
|
});
|
|
// dd($data);
|
|
return $data;
|
|
}
|
|
|
|
public function headings(): array {
|
|
return $this->columns;
|
|
}
|
|
}
|