mardi 26 janvier 2016

Laravel 5.1 - Overloaded routes

I have a homegrown, Laravel 5.1 base application on top of which I build specific applications. The base application uses a named route for login, naturally called "login", which listens for GET /login.

In one of my specific applications, I attempted to overload that route to send the requests to a different controller. It seemed to work for a while, but then it started going to the base application's controller again. I'm sure I changed something to break it, but the problem is that I can't figure out how to fix it again.

My base application routes are all defined in app/Http/Routes/core.php. The relevant route:

Route::get('login', [
    'as' => 'login',
    'uses' => '\MyVendor\Core\Http\Controllers\AuthController@getLogin'
]);

My specific application routes are defined in app/Http/Routes/application.php. The relevant route:

Route::get('login', [
    'as' => 'login',
    'uses' => 'App\AuthController@getLogin'
]);

My app/Http/routes.php adds these routes like this:

require 'Routes/application.php';
require 'Routes/core.php';

No matter which order I require those files, the core route is the one that goes into effect.

My goal is to have the routes defined in 'Routes/application.php' take precedence over any "conflicting" routes in 'Routes/core.php'. Is this possible? How?

EDIT: I just switched this back to have 'core.php' required first, and now the request is going to the right controller. I'm positive this wasn't working a minute ago...

EDIT 2: This is actually a multi-site instance of Laravel 5.1. I have multiple 'application.php' routes files, one for each domain. They were being required inside of a domain route block. Because the 'core.php' routes were needed for each site, that file was required outside of the domain blocks. When it is included inside of the domain block, everything works as expected, i.e. the most recent definition for a route is the effective route. Does this behavior sound like a bug? Can anyone explain why it behaves this way?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire