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?

+3


source to share


1 answer


In config / app.php, in the providers array, put the package service provider before App\Providers\RouteServiceProvider::class,

, and then in the routes web.php

you can override it with your custom route.



+7


source







All Articles