Level 102
Try checking api.php in the routes directory
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
So I am trying to optimize my application but it says it is using closure. I checked web.php and all the routes point to a controller
Web.php
Route::get('/',['as' => 'site.home', 'uses' => 'BlogController@index']);
Route::get('contact', ['as'=>'site.contact', 'uses' => 'BlogController@contact']);
Controller
public function index()
{
if(Session::get('locale') == null)
{
Session::put('locale', 'en');
}
$posts = Posts::with('publishUser')->orderby('created_at', 'desc')->limit(3)->get();
return view('pages.home', ['posts' => $posts]);
}
public function contact(){
return view('pages.contact');
}
After Running
php artisan optimize
I get this
Unable to prepare route [api/user] for serialization. Uses Closure.
at vendor/laravel/framework/src/Illuminate/Routing/Route.php:1150
1146| */
1147| public function prepareForSerialization()
1148| {
1149| if ($this->action['uses'] instanceof Closure) {
> 1150| throw new LogicException("Unable to prepare route [{$this->uri}] for serialization. Uses Closure.");
1151| }
1152|
1153| $this->compileRoute();
1154|
I am using Laravel Nova as well. So I am not sure where can I find all the routing so that I can change them for optimisation.
There you go. Either remove it or change it to use a controller
Route::middleware('auth:api')->get('/user', 'UserController@show');
Please or to participate in this conversation.