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

peterpan26's avatar

laravel excel export a select instead of table , how to return?

i have a raw query i want to export using maatwebsite excel. but usually when i do it is with tables, and this time it's a select, i'm not sure how to do it because usually the queryes do like : "DB::table("tableReport")" and this time its with a DB::select("sql")...

0 likes
6 replies
tykus's avatar

Both of DB::select and DB::table query results will be a Collection of stdClass objects; so, where is the problem?

peterpan26's avatar

@tykus when i press export it says on the title base table or view not found althouth i'm clickinig export from it's view... its not a table and on model i got it as protected $table

tykus's avatar

@peterpan26 you're going to need to share the full error message. The error base table or view not found suggests you are either (i) using the wrong table name (ii) the wrong connection (iii) need to run migrations (iv) ...

peterpan26's avatar

@tykus the only difference from the other exports is as i said above, the other queries are made with DB::table('tablename') its made with DB::select('rawsql') , and its not an index, its instead of index, a show() , the only error i get more is a code 500, and on title of the page says base table or view not found. i can't even read it entirely but yes its that error

tykus's avatar

@peterpan26 can you show the DB::select query - it is impossible to diagnose the issue if you don't share some useful information.

peterpan26's avatar

i had to create the table. the doubt now is how to insert and update without letting it duplicate keys, the query has subqueries and unions inside it, i'm now being able to find how to update it

Please or to participate in this conversation.