我按照文档创建了一个自定义包。 ( https://laravel.com/docs/5.2/packages#routing )
我在自定义路由文件中添加了一个路由,它在使用“php artisan route:list”检查时出现,但我得到 NotFoundHttpException。
我使用“php artisan route:clear”来清除路由缓存,但问题仍然存在。
如果我在主应用程序路由文件中添加路由,则工作正常。
服务提供商:
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
$this->publishes([
__DIR__ . '/../database/migrations/' => database_path('migrations')
], 'migrations');
if (! $this->app->routesAreCached()) {
require __DIR__.'/../Http/routes.php';
}
}
自定义路由文件:
Route::get('foo', function () {
return 'Hello World';
});
最佳答案
对于您在此处提供的信息,我不能只给出明确的答案。
如果你的包结构是这样的
PackageMainDir
- src
- Controllers
- Migrations
- Models
PackageServiceProvider.php
Routes.php
- test
- vendor
composer.json
phpunit.xml
您的 PackageServiceProvider.php 中将包含以下代码:
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
$this->publishes([
realpath(__DIR__.'/Migrations') => $this->getDatabasePath().'/migrations',
]);
if (! $this->app->routesAreCached()) {
require_once(__DIR__ . '/Routes.php');
}
}
我希望不要迟到,否则其他用户将从我的回答中获益。
关于php - 找不到 Laravel 5.2 自定义包路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35970906/