Home > database >  How to select database with dot in its name with laravel?
How to select database with dot in its name with laravel?

Time:06-30

i have a project to show database value... but, the database name has dot in it. my database name is "t.produk".

How can i select the database in laravel? i run it and got an error says it invalid like below

enter image description here

EDIT: and i also did it with just string, came out error too : Here the picture

CodePudding user response:

First of all - avoid naming database tables like that. You should not use any dots there. It could be t_produk as example.

But table name should be descriptive so go for something like products. Than name your entity as Product.

You get this error here because you can't set variable as (t.produk). You should pass a string as I see here. So do it like this:

protected $table = 't.produk';

EDIT:

I saw the error with a string variable. So now you see why the current table naming you choose is quite not good. DB reads it as follows:

select from database t table produk

If you will name your table like t_produk problem should be no longer here.

CodePudding user response:

My bad, so the tables name can't have dot in it. noted. Btw y'all thanks for the answers :)

  • Related