Support the ongoing development of Laravel.io →
Eloquent Laravel

Hello,

I have a project where all database tables got a prefix. But now I have the problem that one database table (external from Laravel) has no prefix and I can't attach it to one. and I can't attach it to a prefix (there are other programs accessing this table). access this table).

When a query is performed on the data, the prefix is appended to the external table. This results in an error message, because of course this table does not exist.

Have also tried it with protected $table = 'employee' - Without success.

Example:

external table: employee

Query in Laravel: lim_employee

Target:

external table: employee

Query in Laravel: employee

Last updated by @veritexx 3 years ago.
0

Can you tell me how you prefix every table? Have you defined some model scope that prefixes all your tables before accessing by the eloquent?

0

The Profix comes from the database connection.

0

You can create two connections In your app/config/database.php like

'mysql' => [
            'driver' => 'mysql',
            'url' => env('DATABASE_URL'),
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => 'lim_',
            'prefix_indexes' => true,
            'strict' => true,
            'engine' => null,
            'options' => extension_loaded('pdo_mysql') ? array_filter([
                PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
            ]) : [],
        ],

        'mysql_no_prefix' => [
            'driver' => 'mysql',
            'url' => env('DATABASE_URL'),
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'prefix_indexes' => true,
            'strict' => true,
            'engine' => null,
            'options' => extension_loaded('pdo_mysql') ? array_filter([
                PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
            ]) : [],
        ],

and in your Employee.php model you need to specify the connection property as

protected $connection = 'mysql_no_prefix';
Last updated by @faisal 3 years ago.
0

Sign in to participate in this thread!

PHPverse

Your banner here too?

Veritexx veritexx Joined 19 Jan 2020

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.