我正在设置一个使用自定义包和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路线的输出
2 回答
来自Laravel 5.3文档:
您的问题是,您的包中的 routes.php 文件未包含在您的项目中 . 要实现这一点,您应该将以下代码放在包的 ServiceProvider 中:
在docs中阅读更多相关信息 .
Update 尝试按照以下方式制作您的路线(使用群组):
在Laravel 5.3中,通过使用“web”中间件组,会话中间件被添加到路由中,auth为我工作 .