Laravel 4 workbench routing to package

I've 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 organized and separate from the rest of the application.

So, I created a composer package as vendor / admin.

then i added these lines as documented 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 route.php file in the vedor / admin / directory to route the entire administration area in this file.

after I started ' php artisan dump-autoload

and I ended up with this artisan grade php artisan config:publish vendor/admin

'

Now I want to use this package for route mysite.com/admin and I want the route.php file in the package to display the routing for this URI in order to do this:

  • Do I need to modify my app /routes.php?
  • How can I make a vendor / admin / src / routes.php file to route for all mysite.com/admin routes?

Thank.

+3


source to share


1 answer


No, you don't need to edit app/routes.php

. As long as it doesn't contain any routes admin

that might clash with those in your package, you can leave it that way.

The route file in the package can be used as "normal" app/routes.php

. An easy way to deal with routes admin

is to have a group of prefixes:



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

      

Also, make sure the package is loaded correctly! One part is registering a service provider . Assuming your package namespace admin

you need to add Admin\AdminServiceProvider

to the vendor array in app/config/app.php

. Additional Information

+1


source







All Articles