Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

hussein4's avatar

export to excel file one specific row records

using maatweb / Excel package i need to export specific row records to excel file where the current page id is viewing

in my VlistController

public function export()
    {
        Excel::create('Company List', function($excel)
        {
            $excel->sheet('companies', function($sheet)
            {
                $data = Vlist::all();
                $data = json_decode(json_encode($data),true);
                $companies = [];
                foreach ($data as $key => $value) {
                    $company['vname']= $value['vname'];
                    $company['vaddress']= $value['vaddress'];
                    
                    $companies[] = $company;
                }
                $sheet->fromArray($companies);
            });
        })->download('xlsx');
    }

in my routes file

Route::get('/vlist/{vlist}/export' , 'VlistController@export');

in my show view

<li><a href="{{ action('VlistController@export', [$vlist->id])  }}"><i class='fa fa-link'></i> <span>Export Supplier : {!! $vlist->vname !!}</span></a></li>

the above controller code list all the records in excel sheet and i need only one specific record with the active id .

0 likes
0 replies

Please or to participate in this conversation.