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

ahm750's avatar

route:cache returns error

When I use 'php artisan route:cache', it returns an error:

Route cache cleared!
  [LogicException]
  Unable to prepare route [api/user] for serialization. Uses Closure.
0 likes
4 replies
jeffdavis's avatar

That is odd because there is a closure in the routes/api.php by default. You would have to comment the Closures out. This means the api/user route and the welcome route as well.

ahm750's avatar

@jeffdavis Yea I commented that closure. But I am using the auth facade provided by Laravel. If I comment this closure, it won't have any affect on the authorization?

jeffdavis's avatar

If you need the api/user route, then you have to change it from a closure to something else. If you send it to a controller, then it will be cacheable.

I am actually talking about something that I haven't tried myself yet, but that seems right.

Please or to participate in this conversation.