Reputation: 721
I created a custom package following the documentation. (https://laravel.com/docs/5.2/packages#routing)
I added a route in the custom routes file, it appears when checking with "php artisan route:list" but I get NotFoundHttpException.
I used "php artisan route:clear" to clear the routes cache but the issue persists.
If I add the route in the main app routes files works fine.
Service provider:
/**
* 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';
}
}
Custom routes file:
Route::get('foo', function () {
return 'Hello World';
});
Upvotes: 3
Views: 1381
Reputation: 1
I had the same issue, I solved it this way
public function boot()
{
$path = realpath(__DIR__.'/../');
$this->loadRoutesFrom($path.'/Routes/web.php');
$this->loadViewsFrom($path.'/Resources/views/Formato','formato');
}
public function register()
{
}
I hope this can be useful
Upvotes: 0
Reputation: 674
I also same experience for that after some research and solved it! please edit your code in the package service provider file function boot()
.
public function boot()
{
if (! $this->app->routesAreCached()) {
require __DIR__ . '/Routes.php';
}
}
After this run the php artisan config:cache
code in cmd i solved this issue.
Upvotes: 0
Reputation: 3244
Solved it, I don't know why but after trying php artisan config:cache
, changes in config/app.php were considered, and the custom service provider loaded the boot( ) method.
Upvotes: 0
Reputation: 1663
For the informatie you give here i cannot just give a clear answer.
If your package structure is like this
PackageMainDir
- src
- Controllers
- Migrations
- Models
PackageServiceProvider.php
Routes.php
- test
- vendor
composer.json
phpunit.xml
You will have in your PackageServiceProvider.php the following code:
/**
* 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');
}
}
I hope its not to late and otherwise other user will have the profit of my answer.
Upvotes: 1