I just ran into this issue and have a simple solution that does not require the user to modify configuration files.
In the boot method of my service provider, I simply create the binding to my middleware:
/** @inheritdoc */
public function boot()
{
$_configPath = realpath(__DIR__ . '/../../config');
$_configFile = $_configPath . DIRECTORY_SEPARATOR . 'partner.php';
$_routeFile = $_configPath . DIRECTORY_SEPARATOR . 'routes.php';
// Add our routes...
if (file_exists($_routeFile)) {
$this->singleton('auth.partner', function ($app) {
return new AuthenticatePartner($app);
});
/** @noinspection PhpIncludeInspection */
include $_routeFile;
}
// Config
if (file_exists($_configFile)) {
$this->publishes([$_configFile => config_path('partner.php'),], 'config');
}
}
You see I register auth.partner in the IoC. So the next bit includes my routes.php file that is included with my service:
\Route::group(['middleware' => 'auth.partner'], function () {
\Route::resource('partner', 'PartnerController');
});
Here I'm simply specifying the middleware for a group, then my controller is nestled inside comfortably. Works great.
This is 5.1 btw