How to return database table name in Laravel

前端 未结 11 587
执念已碎
执念已碎 2020-12-28 13:28

Is there a way that I can get the current database table in use by the model that I\'m in? I see that there is a table() function in Laravel/Database/Eloquent/model.php but

11条回答
  •  余生分开走
    2020-12-28 13:30

    Based on tailor Otwell's answer you could use something like this:

    with(new Model)->getTable();
    

    Note: tested on versions 5.x, 6.x, 7.x, 8.x and it works well.

提交回复
热议问题