Framework: [7.x] Unable to prepare route [api/user] for serialization. Uses Closure. (LogicException)

Created on 7 Mar 2020  路  8Comments  路  Source: laravel/framework

  • Laravel Version: 7.0.6
  • PHP Version: 7.4.2
  • Database Driver & Version: MariaDB 10.4.11 (XAMPP)

Description

I have installed laravel 7 in my local server. When I run php artisan route:cache command then laravel return error:

LogicException

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

This problem was not in previous versions of the framework.

All 8 comments

@devmansurov
When route has closures you can not cache route so you need to map with controller action

This problem was not in previous versions of the framework.

Closure routes were never supported so this definitely was.

I am facing this problem with laravel 7 from laravel5.3. Please help me.

This issue still exists, even using a controller method didn't help at all. Laravel still throws the same error

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

In Laravel 8 it'll be possible to cache routes using closures.

I have same issue ( laravel 7.23.2 ), after run php artisan optimize then laravel return error

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

My web root

Route::get('/', function () {
    return view('welcome');
});

Going to lock this to prevent more "I have this too" comments.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RomainSauvaire picture RomainSauvaire  路  3Comments

kerbylav picture kerbylav  路  3Comments

ghost picture ghost  路  3Comments

PhiloNL picture PhiloNL  路  3Comments

gabriellimo picture gabriellimo  路  3Comments