Laravel 5.4 - How to override a route defined in a package?
I created a package in Laravel 5.4 that installs the basic backoffice. This package contains several routes that the controllers within the package use. What I want to do is override the routes defined in the package in my application in order to connect custom controllers. For example, if I have a route
Route::get('login', [
'as' => 'admin.login',
'uses' => 'Auth\LoginController@showLoginForm'
]);
defined in my package to be used Vendor\Package\Controllers\Auth\LoginController
, I want to define a route for my application that will override this and use App\Controllers\Auth\LoginController
.
Doing the obvious approach to defining a route in application route files does not work for application route files that run before the package route file, so the package definition will prevail.
Is there a way to do something like this?
I also tried to get the specific route in RouteServiceProvider
and use the method uses
to set the controller that should be used to resolve it, like
public function boot()
{
parent::boot();
Route::get('admin.login')->uses('App\Http\Controllers\Admin\Auth\LoginController@showLoginForm');
}
but it also prevents what it pretends to do.
Any hints on what I am doing wrong?
source to share