我正在设置一个使用自定义包和laravel身份验证中间件的laravel 5.3应用程序。当我在laravel / packages / vendor / packageName / src / routes.php中定义路由时就像
中的情况一样Route::get('member/list', function() {
return 'member lists here';
})->middleware('auth');
它重定向到RedirectIfAuthenticated Middleware中定义的localhost:8000 / dashboard url但是当我在resources / routes / web.php中定义路由时,它会根据需要进行路由和授权。
我有什么问题,或者我需要检查的东西?
--- ---更新 以下是我的ServiceProvider类的片段
namespace Beansoft\PractitionerIMS;
use Illuminate\Support\ServiceProvider;
class PractitionerIMSServiceProvider extends ServiceProvider {
public function register() {
$this->app->bind('practitionerims', function($app) {
return new PractitionerIMS;
});
}
public function boot() {
//load the routes file
if (!$this->app->routesAreCached()) {
require __DIR__ . '/Http/routes.php';
}
}
应用/配置/ app.php
'providers' => [
/*
* Laravel Framework Service Providers...
*/
Illuminate\Auth\AuthServiceProvider::class,
Illuminate\Broadcasting\BroadcastServiceProvider::class,
Illuminate\Bus\BusServiceProvider::class,
Illuminate\Cache\CacheServiceProvider::class,
Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class,
Illuminate\Cookie\CookieServiceProvider::class,
Illuminate\Database\DatabaseServiceProvider::class,
Illuminate\Encryption\EncryptionServiceProvider::class,
Illuminate\Filesystem\FilesystemServiceProvider::class,
Illuminate\Foundation\Providers\FoundationServiceProvider::class,
Illuminate\Hashing\HashServiceProvider::class,
Illuminate\Mail\MailServiceProvider::class,
Illuminate\Notifications\NotificationServiceProvider::class,
Illuminate\Pagination\PaginationServiceProvider::class,
Illuminate\Pipeline\PipelineServiceProvider::class,
Illuminate\Queue\QueueServiceProvider::class,
Illuminate\Redis\RedisServiceProvider::class,
Illuminate\Auth\Passwords\PasswordResetServiceProvider::class,
Illuminate\Session\SessionServiceProvider::class,
Illuminate\Translation\TranslationServiceProvider::class,
Illuminate\Validation\ValidationServiceProvider::class,
Illuminate\View\ViewServiceProvider::class,
Beansoft\PractitionerIMS\PractitionerIMSServiceProvider::class,
/*
* Package Service Providers...
*/
//
Yab\Laracogs\LaracogsProvider::class,
/*
* Application Service Providers...
*/
App\Providers\AppServiceProvider::class,
App\Providers\AuthServiceProvider::class,
// App\Providers\BroadcastServiceProvider::class,
App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class,
],
php artisan route的输出
答案 0 :(得分:0)
来自Laravel 5.3文档:
要定义程序包的路由,只需要从程序包服务提供程序的引导方法中获取routes文件。在路径文件中,您可以使用Illuminate \ Support \ Facades \ Route外观来注册路径,就像在典型的Laravel应用程序中一样:
您的问题是,您的包中的 routes.php 文件未包含在您的项目中。为实现此目的,您应将以下代码放入包中 ServiceProvider :
public function boot()
{
if (! $this->app->routesAreCached()) {
// customize this reference according to your package structure
require __DIR__.'/../../routes.php';
}
}
在docs中了解更多相关信息。
<强>更新强> 尝试使您的路线如下(使用组):
Route::group(['middleware' => 'auth'], function() {
Route::get('member/list', function() {
return 'member lists here';
});
});
答案 1 :(得分:0)
在Laravel 5.3中,通过使用“网络”中间件组,将会话中间件添加到路由中,并且auth对我有效。
Route::group(['middleware' => ['web','admin']], function () {
Route::get('/admin/somepage', '\MyPackage\SomeController@somepage');
});