z-song / laravel-admin

Build a full-featured administrative interface in ten minutes
https://laravel-admin.org
MIT License
11.15k stars 2.82k forks source link

new admin path #5783

Open GurgenYeranosyan opened 1 year ago

GurgenYeranosyan commented 1 year ago

how to make a new path like /admin for example /new_admin with config file like new_admin.php, folder like app/new_admin

alexoleynik0 commented 1 year ago

Hello. First thing I want to do is ask you (or anyone) to reconsider, because anything you're trying to achieve probably could be done with Roles and Permissions.

That being said, here's some tricky solution I came out with to your request:

  1. Create a directory app/AdminNew.
  2. Copy app/Admin/Controllers/HomeController.php to app/AdminNew/Controllers/HomeController.php and made changes in index method so you can see them after.
  3. Copy routes.php and bootstrap.php and edit as you need (mainly you need to change path for '/' route to AdminNew/Controllers/HomeController@index).
  4. Copy config/admin.php to config/admin_new.php.
  5. Change configs there as you need, but firstly these:
    'route' => [
    'prefix' => 'admin_new',
    'namespace' => 'App\\AdminNew\\Controllers',
    'middleware' => ['web', 'admin'],
    ],
    'directory' => app_path('AdminNew'),
    'bootstrap' => app_path('AdminNew/bootstrap.php'),
    'extension_dir' => app_path('AdminNew/Extensions'),
  6. You probably also want to make copy of all DB admin_ tables and change config 'database' in your new config file.
  7. In App\Providers\AppServiceProvider's register method add this:
    if (0 === strpos(request()->path(), 'admin_new')) {
    config(['admin' => config('admin_new')]);
    }
  8. That's actually it. Now check that both /admin and /admin_new routes work and output data from different (if that's what you need) Controllers.

At this point you'll probably have many new Errors to fix, so good luck!