3
votes

I have been working with laravel 4 for some time now and i needed to create an admin area so i decided to use a package to keep things all organized and separated from the rest of the application.

So i created a package with composer as 'vendor/admin'.

then i added those lines as documemented on laravel site

AdminServiceProvider.php

public function boot()
    {
        $this->package('vendor/admin', 'admin');
        include __DIR__.'/../../routes.php';
 }


public function register()
    {
        //
        $this->package('vendor/admin');

    }

I also created a routes.php file in vedor/admin/ directory to route all admin area in this file.

following i run the 'php artisan dump-autoload' and i finalized with this commend on artisan 'php artisan config:publish vendor/admin'

now i wanna be able use this package for mysite.com/admin route and i want the routes.php file in the package to render the routing for that URI, to do that:

  1. Do i need to modify my app/routes.php?
  2. How can i make vendor/admin/src/routes.php file to do the routing for all mysite.com/admin routes?

Thanks.

1

1 Answers

1
votes

No you don't need to edit app/routes.php. As long as it doesn't contain any admin routes that could collide with the ones in your package you can leave it that way.

The routes file in a package can be used like the "normal" app/routes.php. An easy way to deal with admin routes is to have a prefix group:

Route::group(array('prefix' => 'admin'), function(){
    // all your admin routes. for example:
    Route::get('dashboard', '...');
    // will match GET /admin/dashboard
});

Besides that, make sure you're package gets loaded correctly! One part being registering the service provider. Assuming the namespace of your package is Admin you need to add Admin\AdminServiceProvider to the providers array in app/config/app.php. More information