I am attempting to create a composer package for Laravel 6 but I can not get my main route /
to override the default /
route included with the base Laravel installation.
My package route does works when I comment out the base /
route provided by laravel so it is being registered by the package.
It doesn't make any different if I include my package's service provider before or after the RouteServiceProvider in the config/app.php
file.
What am I missing here? How do I ensure my package routes have priority?
Here are the relevant bits of code:
config/app.php
/*
* Application Service Providers...
*/
App\Providers\AppServiceProvider::class,
App\Providers\AuthServiceProvider::class,
// App\Providers\BroadcastServiceProvider::class,
App\Providers\EventServiceProvider::class,
Wheelmaker\LaravueSpa\LaravueSpaServiceProvider::class, // MY SERVICE PROVIDER
App\Providers\RouteServiceProvider::class,
The relevant section of LaravueSpaServiceProvider
public function boot()
{
$this->loadRoutesFrom(__DIR__.'/routes/web.php');
...
}
My Package's web.php
route file:
<?php
Route::get('/', function(){
$initData = [
'appName' => config('app.name'),
'user' => Auth::user(),
];
return view('laravue-spa::app', compact('initData'));
})->middleware(['web']);
This may be late but for someone else:
You can ask the user to disable the auto package discovery in their composer.json
and then manually register the package's Service Provider before the RouteServiceProvider
in config/app.php
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.