What are you looking to do?
I'm curious as well, I'd like to know if its possible to do something like /terms to /terms-of-service or /register to /join.
Granted we can also just create our own routes, then call the needed view.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Is there an easy way to overwrite Spark's routes, without modifying the source files?
What are you looking to do?
I'm curious as well, I'd like to know if its possible to do something like /terms to /terms-of-service or /register to /join.
Granted we can also just create our own routes, then call the needed view.
@zanematthew Well, to simply use /login in my own routes.php file.
I would like to overwrite the same routes that Spark is already using.
That way, I can translate my (Spark's) routes with a localization package.
I guess I could extend Spark's service provider class, and change the method that adds Spark's routes, but it's just too much of a hassle.
Have you found any clean solution @jlmmns ?
@EvenStevens @jlmmns you can just add the route to your app/Http/routes.php file. Spark will use whats in your routes.php file first, then use its own.
Route::get('/login', function(){
// your custom logic here
dd('hi');
});
Is that not what your looking for?
That does not work because the routes in the vendor routes.php file (i.e. vendor\laravel\spark\src\Http\routes.php) take precedence over the app/Http/routes.php file.
I believe it has to do with the order these files are loaded (which I did not find yet)
@EventFellows Thats odd, I tested that and it worked for me.
I just checked, and if it makes a difference it is the first line in my routes.php file.
@zanematthew That's strange, it definitively does not do it on my setup, not on homestead and also not on the server.
Can you confirm that you have not removed that route from the spark routes.php file? That would be the only thing that comes to my mind for this difference...
Where is the priority of the different route files defined - seems I have to digg deeper here?
@EventFellows That is very odd
I'm using Spark version 1.0.13.
Here's an image of my custom routes.php, and the default unchanged routes.php along with the output in the browser. Yes, I'm using homestead as well.
Let me know if you want more info.
https://s32.postimg.org/vymil4m85/Screen_Shot_2016_07_07_at_2_13_39_PM.png
@zanematthew Can you try placing your /login route within the 'web' middleware?
Not sure if it matters, but maybe it has to do with that?
@jlmmns Tested with this:
Route::get('/login', function(){
dd('hi'); // this is ignored
});
$router->group(['middleware' => ['web']], function ($router) {
$router->get('/login', 'WelcomeController@show'); // this works
});
@zanematthew Hm, then I guess it has been fixed in the version you're using...
I haven't tested it anymore with a version higher than 1.0.7, I think.
@EventFellows Are you using the latest version of Spark?
I am using Spark 1.0.13 and it has that problem, too. But strangly enough I double checked with another spark install that I did back in the days to play around - there is works like mentioned by @zanematthew ( same environment, same machine)
So I feel it must have something to do with anything I changed during develpment, though not doing anything (consciously) in the vendor files or route files....
hmm, this has me wondering as well, might be something with the way Spark is installed? From my understanding you can use the Spark installer, or composer.
https://spark.laravel.com/docs/1.0/installation#spark-installer
Ok, got it after quite som trial-and-error.
These two files must be listed in \config\app.php in providers-array in this order to allow overwrites of spark-routes.
Laravel\Spark\Providers\SparkServiceProvider::class,
App\Providers\RouteServiceProvider::class,
I installed spark the windows way (like described in official documentation) and there was nothing mentioned about a specific oder of providers being needed.
Hope this also works for you @jlmmns and others with the same issue in future.
@EventFellows Well that totally makes sense... :)
If I might make a suggestion, if you are going to experiment with routes and who/what has precedence, don't forget to clear the caches with artisan or you may end up chasing your tail.
Please or to participate in this conversation.