I have to export excel by joining two tables but I can't understand the way to complete this I'll attach the screenshot of my tables and codes. Please help me to solve these issues.
Table One: Decoration
Table Two: Decoration Price
Sample Data
Decoration.php Model Page
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
class Decoration extends Model
{
protected $table='decoration';
protected $fillable=['deco_print_type','deco_prod_code','deco_supp_code','deco_name','deco_logo_setup_charge','deco_main_type','deco_is_main_type','deco_weight_for_sorting','deco_priority','deco_is_shown_to_clients'];
public static function getDecoration()
{
$Decoration = DB::table('decoration')
->select('deco_print_type','deco_name','deco_prod_code','deco_priority','deco_rank','deco_logo_setup_charge','deco_is_shown_to_clients')
->where('deco_flag','=','1')->orderBy('deco_print_type','ASC')->get()->toArray();
foreach ($Decoration as $deco)
{
$decoPrice = DB::table('decoration_price')
->select('decp_quantity','decp_quantity')
->where('decp_print_type','=',$deco->deco_print_type)
->orderBy('decp_qty_break_leve','ASC')->get()->toArray();
//$Decoration[$i]=$decoPrice;
}
return $Decoration;
}
}
Exports/DecorationExport.php Page code
<?php
namespace App\Exports;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Illuminate\Support\Facades\DB;
use App\Decoration;
use App\Decoration_Price;
class DecorationExport implements FromCollection,WithHeadings
{
public function headings(): array
{
// TODO: Implement headings() method.
return [
"Decoration code",
"Decoration name",
"Main decoration",
"Priority",
"Rank",
"Setup Charge",
"Shown_to_clients",
"A2",
"B2",
"A3",
"B3",
"A4",
"B4",
"A5",
"B5",
"A6",
"B6",
"A7",
"B7",
"A8",
"B8",
"A9",
"B9",
];
}
/**
* @return \Illuminate\Support\Collection
*/
public function collection()
{
return collect(Decoration::getDecoration());
}
}
Decoration Route Function for download
public function DecoBulkExport()
{
$decoration = new DecorationExport;
return Excel::download($decoration,'Decoration.csv');
}
When I click the export button data file should become like this.
Please Help me or advise me on how to do this



