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

DewiH's avatar
Level 1

Append data to spreadsheet

I've been trying to export data to Googlesheet using the package revolution/laravel-google-sheets : every simple data can be exported with no problem, but when it has relation belongsToMany, it's not working.

In my controller : 

public function store(Request $request)
    {
        $clubRegistration = ClubRegistration::create($request->all());
        $clubRegistration->clubs()->sync($request->input('clubs', []));

        $append = [
                $clubRegistration->no,
                $clubRegistration->status ? $model->status->name : '',
                $clubRegistration->payment_status ? $model->payment_status->name : '',
                $clubRegistration->student ? $model->student->last_name : '',
                $clubRegistration->student ? $model->student->first_name : '',
                $clubRegistration->clubs ? $clubRegistration->clubs->pluck('name')->implode(', ') : '', 
                $clubRegistration->created_by->name ?? '',
                $clubRegistration->created_at,
                $clubRegistration->updated_at,
            ];
            $appendSheet =  Sheets::spreadsheet('***')
                            ->sheetById('***') 
                            ->append([$append]);

			return redirect()->back();	
   }

In the sheet, every column is filled, except the clubs' column. I've tried using the same method for Excel export, and it's working.

0 likes
1 reply

Please or to participate in this conversation.