Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5.2 custom package route not found

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';
});
like image 397
Dorin Niscu Avatar asked Dec 04 '25 09:12

Dorin Niscu


1 Answers

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.

like image 74
J. Overmars Avatar answered Dec 07 '25 00:12

J. Overmars



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!