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

jan.kremlacek's avatar

how to remove some Spark default routes? (or in general from any other package..)

hey there ..

maybe, it's a very stupid question; as it seems to me that there must be very elegant and simple solution, but ..

  • spark is a package to Laravel ..
  • and I want to remove some default routes (let's say for example the /terms route, just one)
  • is there any way how to remove the route please?

I can override the route with my own, and for example redirect somewhere, but in such a case route cache does not work, as it throws an exception like using Closure in routes ..

of course, I can remove them from /spark/src/Http/routes.php; but it's code from repo and will change with next update .. and even it's terrible way to adjust someone else's code ;) ..

last, but not least, I know the cache is not necessary; but I want to remove some routes as I implement totally different login method and want to keep my production site out of deprecated routes ..

thank you for help.

0 likes
5 replies
d3xt3r's avatar
d3xt3r
Best Answer
Level 29

I can override the route with my own, and for example redirect somewhere, but in such a case route cache does not work, as it throws an exception like using Closure in routes ..

Then don't use closure. Have a dummy controller method.

If the routes come with the package, there's no way of getting rid of it completely. At best, you can have your server not serve them. You can block them in server's config file as well if you wish.

jan.kremlacek's avatar

sometimes the solution is easy ;) .. thank you .. I can get rid of them at nginx, yes! simple! thank you ..

if I may ask more please, when I was talking about overriding routes, I did not use Closure, let me tell an example ..

there is a route in Spark (for example): $router->get('/terms', 'TermsController@show');

if I override it in app/Http/routes.php like: Route::get('/terms', 'AnotherController@anotherMethod');

the php artisan route:cache still ends with [Exception] Serialization of 'Closure' is not allowed ..

is there a way please how to override the route and still cache routes? (it is not a matter of life and death, but I like to know)

thank you anyway. Jan.

d3xt3r's avatar

If it says [Exception] Serialization of 'Closure' is not allowed .. then there must be a route using closure, find out which using php artisan route:list

1 like
Kairu's avatar

I know this is a month old now, but I'm only just encountering this issue. Trying to override the Team profile photo route so I can use my own implementation and I'm getting the same [Exception] Serialization of 'Closure' is not allowed error, despite having no closure based routes, I know they can't be cached. I have the Spark service provider loaded before my own route service provider, so I'm not sure why it's not overriding properly.

Please or to participate in this conversation.