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

gazd1977's avatar

Unable to prepare route [api/user] for serialization. Uses Closure.

Hi All,

Has anyone come across the below error when running php artisan route:cache

  LogicException  : Unable to prepare route [api/user] for serialization. Uses Closure.

  at /home/vagrant/code/project4/vendor/laravel/framework/src/Illuminate/Routing/Route.php:917
    913|      */
    914|     public function prepareForSerialization()
    915|     {
    916|         if ($this->action['uses'] instanceof Closure) {
  > 917|             throw new LogicException("Unable to prepare route [{$this->uri}] for serialization. Uses Closure.");
    918|         }
    919|
    920|         $this->compileRoute();
    921|

I havent made a change to the api/user route which is as below:

Route::middleware('auth:api')->get('/user', function (Request $request) {
    return $request->user();
});

0 likes
1 reply
tykus's avatar
tykus
Best Answer
Level 104

If you want to cache your routes, you cannot use Closure routes.

Just remove it if you're not using it. If you need it, then use a Controller action

Please or to participate in this conversation.