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

FounderStartup's avatar

Error after php artisan route:cache on production server

I am getting this error after php artisan route:cache on production server :

LogicException

Unable to prepare route [dashboard] for serialization. Another route has already been assigned name [dashboard].

at vendor/laravel/framework/src/Illuminate/Routing/AbstractRouteCollection.php:218 214▕ $route->name($name = $this->generateRouteName()); 215▕ 216▕ $this->add($route); 217▕ } elseif (! is_null($symfonyRoutes->get($name))) { ➜ 218▕ throw new LogicException("Unable to prepare route [{$route->uri}] for serialization. Another route has already been assigned name [{$name}]."); 219▕ } 220▕ 221▕ $symfonyRoutes->add($route->getName(), $route->toSymfonyRoute()); 222▕

  +19 vendor frames

20 artisan:37 Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

Few Routes :

Route::middleware(['auth:sanctum,web', 'verified'])->get('/dashboard', function () {
    return view('dashboard');
})->name('dashboard');


// User Routes

Route::middleware(['auth:sanctum,web', 'verified'])->get('/dashboard', function () {
	$id = Auth::user()->id;
    $user = User::find($id);
    return view('dashboard',compact('user'));
})->name('dashboard');

0 likes
3 replies
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

Why are they the same name and url?

Either way.. Move the second to a controller

The first you can use the view() route method

Route::middleware(['auth:sanctum,web', 'verified'])->view('/dashboard', 'dashboard')->name('dashboard');
1 like
Sinnbeck's avatar

@FounderStartup This is actually just routing. When you cache routes, laravel converts them to a simple lookup list. But there can be stuff it cannot convert, and you get that error. It is easy to fix, but simply moving logic out of the route file and into a controller (where it belongs)

1 like

Please or to participate in this conversation.