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

vincej's avatar
Level 15

Anyone know what authentication middleware to apply to Laravel Excel?

HI, I Tried using the usual $this->middleware('auth'); inside the constructor of the Export file where the collection lives and got this error:

Call to undefined method App\Exports\RawDataExport::middleware()

I have poked around SO and Googled extensively, and can see what what is probably an obvious mistake.

Any advice ?

Many thanks !

0 likes
3 replies
bugsysha's avatar
bugsysha
Best Answer
Level 61

That method does not exist on that class. You can use that method on controllers. So in your controller you can add that to the constructor or define middleware in your route file.

vincej's avatar
Level 15

Thanks for that. I always use authentication inside controllers, and in this case that can not work as the route calls Excel immediately. I never use authentication inside a route, so I had totally forgotten that option.

bugsysha's avatar

Thanks for the “Best Answer”. All best.

Please or to participate in this conversation.