How to get the table name of a model?

Asked

Viewed 518 times

0

I need to get the table name that is used by determined model in my written application in Laravel.

In the past, in the Laravel 3, it was only necessary to do this to find out the table name:

   var_dump(MeuModel::$table);

However, in the Laravel 4 >= this property is no longer static, let alone public.

For example:

 class Usuario extends Eloquent
 {
    protected $table = 'tbl_usuarios';
 }

That is, with the property being protected cannot catch it "outside the model instance".

I need, in Controller, I can get the value of protected $table to display it.

Is there any way to do that in the Laravel?

1 answer

0


To get a model’s table name just use the method getTable, which is inherited from Eloquent.

$tabela_usuarios = (new Usuario)->getTable();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.