why?? "Unable to prepare route ... for serialization. Uses Closure."

Published 3 years ago by andy

When I do "route:clear" I get this error:

Unable to prepare route [language/{lang}] for serialization. Uses Closure.

The route that is causing this is:

Route::get('/language/{lang}', function ($lang) {
    Session::put('locale', $lang);
    return Redirect::back();
    });

I'm trying to understand this problem, my questions are:

  1. Why is this happening? Meaning, I based that route off the docs and I can't seem to understand why would a documented suggestion cause an error.

  2. What is a solution or even does anybody have a link to share?

Thanks!

Best Answer (As Selected By andy)
Kryptonit3

@andy

https://github.com/laravel/framework/issues/7319#issuecomment-73362932

Apparently you cannot use route caching if you have ANY route closures. Make a controller and use your logic there and direct your route to the Controller/Method.

Kryptonit3

@andy

https://github.com/laravel/framework/issues/7319#issuecomment-73362932

Apparently you cannot use route caching if you have ANY route closures. Make a controller and use your logic there and direct your route to the Controller/Method.

andy
andy
3 years ago (39,645 XP)

Thanks!

Please sign in or create an account to participate in this conversation.