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

jamesfrancisramos7's avatar

Export to excel but error "Illegal Offset type"

I'm trying to export but it there's an error saying "Illegal Offset type". My code in my UsersController goes like this, please help me experts.

public function userExport()
{
    $users = $this->users->paginate(
            $perPage = 20,
            Input::get('search'),
            Input::get('status'),
            Input::get('emp_status'),
            Input::get('level'),
            Input::get('age'),
            Input::get('gender'),
            Input::get('civil_status'),
            Input::get('role_id'),
            Input::get('birthmonth'),
            Input::get('company'),
            Input::get('branches'),
            Input::get('benefit'),
            Input::get('designation'),
            Input::get('tenure')
            );
            // Input::get('gender')
        return Excel::create('data_function',function($excel) use ($users){
            $excel->sheet('mysheet', function($sheet) use ($users){
                $sheet->fromArray($users);
            });
        })->download('xls');
}
0 likes
10 replies
deansatch's avatar

$users = $this->users->paginate(
            20,
            [
        Input::get('search'),
            Input::get('status'),
            Input::get('emp_status'),
            Input::get('level'),
            Input::get('age'),
            Input::get('gender'),
            Input::get('civil_status'),
            Input::get('role_id'),
            Input::get('birthmonth'),
            Input::get('company'),
            Input::get('branches'),
            Input::get('benefit'),
            Input::get('designation'),
            Input::get('tenure')
        ]
            );

deansatch's avatar

Not sure why you have the Input::get() but since the second arg in paginate() is an array of columns, if you remove those and just leave the names it should be valid.

eg

paginate(20, ['status', 'emp_status', etc...])

jamesfrancisramos7's avatar

it still says array string to conversion.

I put Input::get because i filter the table. And after i filter it i want to export it to excel

@deansatch

deansatch's avatar

does it tell you what line the error is on? Does paginate(20) alone work?

I see you are using fromArray(). So should you not have paginate(20)->toArray() ?

jamesfrancisramos7's avatar

$q->where('username', "like", "%{$search}%"); that's the line that has an error

Please or to participate in this conversation.