Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

NomaD's avatar

eloquent table name with dots

my table name contains dots

    protected $table = 'monitoring.users';

But when i select it splits into peaces

 SQL: select * from `monitoring`.`users`
0 likes
6 replies
RachidLaasri's avatar

You shouldn't be using dots on your table/column names.

3 likes
NomaD's avatar

is it a laravel restriction or ?, i am tring to migrate databases from postgresql to mysql , so postgresql uses schemas and mysql doesnot, so a have to use dots

jimmck's avatar
jimmck
Best Answer
Level 13

In SQL dots (.) separate objects. A schema is a database to MYSQL. In general terms a schema describes an object. You can have a Database schema or Table schema for example. Using the 'dot' gives a more precise naming of a database object. Two tables can contain a column of the same name 'foo'. You specify which one by the table name using 'dot'. So you have table1.foo and table2.foo. Or at the 'database' level myDatabase.table1.foo and yourDatabase.table1.foo. And do not confuse the ability to name a specific database instance as a way to reference a PostGres table and a MySQL table in the same query. You cannot without some help from a class or driver.

1 like
h4w0k's avatar

I found a great solution how to do it in PostgreSQL models. You need to add constructor to you model with DB::raw():


public function __construct(array $attributes = [])
{
    parent::__construct($attributes);

    $this->table = DB::raw('"dot.table"');
}

That's it!

2 likes

Please or to participate in this conversation.