aimeos-laravel icon indicating copy to clipboard operation
aimeos-laravel copied to clipboard

Admin Panel Not Loading When Using Two Different Databases one for aimeos and other for laravel base database.

Open siddharthghedia opened this issue 8 months ago • 8 comments

The admin panel fails to load when configuring Aimeos to use two different databases. When trying to open admin routes URL then gives an unauthorised access error.

I tried the following steps:

  1. Set up and install Aimeos in existing Laravel project.
  2. Configure two different database connections in the config/database.php file.
// for Aimeos database

'mysql_aimeos' => [
            'driver' => 'mysql',
            'host' => env('DB_AIMEOS_HOST', '127.0.0.1'),
            'port' => env('DB_AIMEOS_PORT', '3306'),
            'database' => env('DB_AIMEOS_DATABASE', ''),
            'username' => env('DB_AIMEOS_USERNAME', ''),
            'password' => env('DB_AIMEOS_PASSWORD', ''),
            'charset' => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'stmt'                => ["SET SESSION sort_buffer_size=2097144; SET NAMES 'utf8mb4'; SET SESSION sql_mode='ANSI'"],
            'prefix' => '',
            'prefix_indexes' => true,
            'strict' => true,
            'engine' => null,
            'options' => [
                PDO::ATTR_EMULATE_PREPARES => true,
            ],
        ],

// for laravel database

'mysql' => [
            'driver' => 'mysql',
            'url' => env('DATABASE_URL'),
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', ''),
            'username' => env('DB_USERNAME', ''),
            'password' => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8',
            'stmt'    => ["SET SESSION sort_buffer_size=2097144; SET NAMES 'utf8mb4'; SET SESSION sql_mode='ANSI'"],
            'collation' => 'utf8_unicode_ci',
            'prefix' => '',
            'prefix_indexes' => true,
            'strict' => false,
            'engine' => null,
            'options' => extension_loaded('pdo_mysql') ? array_filter([
                PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
            ]) : [],
        ],
  1. Assign one database connection for the application and another for Aimeos.
  2. Configure admin route to config/shop.php file.
'admin' => ['prefix' => 'store-admin', 'middleware' => ['web']],
'jqadm' => ['prefix' => 'store-admin/{site}/jqadm', 'middleware' => ['web']],
// for aimeos database

'db' => [
            'adapter' => config('database.connections.'.config('database.default', 'mysql').'.driver', 'mysql'),
            'host' => config('DB_AIMEOS_HOST', 'localhost'),
            'port' => config('DB_AIMEOS_PORT', '3306'),
            'socket' => config('database.connections.'.config('database.default', 'mysql').'.unix_socket', ''),
            'database' => config('DB_AIMEOS_DATABASE', ''),
            'username' => config('DB_AIMEOS_USERNAME', ''),
            'password' => config('DB_AIMEOS_PASSWORD', ''),
            'stmt' => config('database.default', 'mysql') === 'mysql' ? ["SET SESSION sort_buffer_size=2097144; SET NAMES 'utf8'; SET SESSION sql_mode='ANSI'"] : [],
            'limit' => 3, // maximum number of concurrent database connections
            'defaultTableOptions' => [
                'charset' => 'utf8',
                'collate' => 'utf8_unicode_ci',
            ],
            'driverOptions' => config('database.connections.'.config('database.default', 'mysql').'.options'),
        ],

// for Laravel database

'db-customer' => [
            'adapter' => 'mysql',
            'host' => '127.0.0.1',
            'port' => '3306',
            'database' => env('DB_DATABASE', ''),
            'username' => env('DB_USERNAME', ''),
            'password' => env('DB_PASSWORD', ''),
            'stmt' => ["SET SESSION sort_buffer_size=2097144; SET NAMES 'utf8'; SET SESSION sql_mode='ANSI'; SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED"],
            'limit' => 2,
            'opt-persistent' => 0,
            'defaultTableOptions' => [
                'charset' => 'utf8',
                'collate' => 'utf8_unicode_ci',
            ],
        ],

  1. Run the following command after configuring database.

php artisan vendor:publish --tag=config --tag=public php artisan migrate php artisan aimeos:setup --option=setup/default/demo:1

  1. Then created a super user

php artisan aimeos:account --super <email>

  1. Attempt to access the Aimeos admin panel.

Additional context

  • Laravel version: ^9.26
  • Aimeos version: ^2023.10
  • PHP version: 8.0

After, above steps I am able to run Aimeos frontend and login. Also, display logged-in user details in frontend profile page but when I try to open admin routes then It says unauthorised to access the page.

Screenshot 2024-06-14 at 6 22 32 PM

I think actually the problem with role because of using different database. Aimeos table don't have users table. I also followed below steps but couldn't make it work. https://github.com/aimeos/aimeos-laravel/issues/267

siddharthghedia avatar Jun 14 '24 13:06 siddharthghedia