If you are encountering the error "Error: Ziggy error: route 'your-route' is not in the route list" the solutions is most likely very simple. This is an error I came across when using Laravel with Inertia.js and Vue.js. There are a couple of things you need to check to get this sorted.
If you are trying to resolve the Error: Ziggy error: route 'your-route' is not in the route list error, this is what you need to do:
So you have a nice working route looking like this:
...
Route::middleware(['auth:sanctum', 'verified'])->get('adverts', [AdvertController::class, 'index'])
->name('advert');
...
Then you copy the route and paste it to create a new similar route. You rename the route and your routes/web.php file looks like this:
...
Route::middleware(['auth:sanctum', 'verified'])->get('adverts', [AdvertController::class, 'index'])
->name('adverts');
Route::middleware(['auth:sanctum', 'verified'])->get('adverts', [AdvertController::class, 'index'])
->name('adverts.my_adverts');
...
Everything seems fine. You have 2 routes with different names. But now you are encountering the Error: Ziggy error: route 'your-route' is not in the route list error.
The reason for this is that both routes are for GET requests, and they both have the same path! Simply changing the path of the second route will sort the problem out:
...
Route::middleware(['auth:sanctum', 'verified'])->get('adverts', [AdvertController::class, 'index'])
->name('adverts');
Route::middleware(['auth:sanctum', 'verified'])->get('my-adverts', [AdvertController::class, 'index'])
->name('adverts.my_adverts');
...
Hope you're having a good day. Check out my YouTube channel if you have a spare 5 mins 🙂