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

yordan1984's avatar

laravel + maatwebsite error

Hello everyone, I am trying to use /maatwebsite library to export excel for the first time, but when I try to export data, the system gives this error:

SQLSTATE[22P02]: Invalid text representation: 7 ERROR: la sintaxis de entrada no es válida para integer: «exportExcel» (SQL: select * from "groups" where "id" = exportExcel limit 1)

Here is my code:

html: a href="{{ route('group.exportExcel') }}"> <i class="fa fa-file-excel-o" </i </a (tags has been removed for post reazons)

web.php: Route::get('/admin/group/exportExcel', 'GroupController@exportExcel')->name('group.exportExcel');

GroupController: public function exportExcel(Request $request){ return Excel::download(new GroupExport(),'group.xls'); }

App/Exports/GroupExport.php:

use App\Group; use Illuminate\Support\Collection; use Maatwebsite\Excel\Concerns\FromCollection;

class GroupExport implements FromCollection { /** * @return Collection */ public function collection() { return Group::all(); } }

Can anyone help me please?

0 likes
3 replies
Sinnbeck's avatar

Please format your code by adding ``` on the line before and after the code.

Sinnbeck's avatar

Oh and my best guess is that you have a route before this one that catches the url..

Something like

Route::get('/admin/group/{id}', 'GroupController@show'); //This route will catch the export request and give that error.. Swap the routes to fix the error.

Route::get('/admin/group/exportExcel', 'GroupController@exportExcel')->name('group.exportExcel');
1 like
neilstee's avatar

@sinnbeck probably that one because of ... where "id" = exportExcel error. Nice catch!

Please or to participate in this conversation.