本文介绍了如何从 Eloquent 模型静态获取表名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
现在我有这个代码来检查 Eloquent 模型连接到哪个表.
Right now I have this code to check to which table an Eloquent model is connected into.
$s = new Something();
dd($s->getTable());
无论如何我可以在不实例化新的 Something
对象的情况下获取表格?
Is there anyway I can get the table without instantiating new Something
object?
我在想类似这些代码的事情:
I was thinking something like these codes:
Something::getTable();
但是会出现..should not be statically调用
错误.
推荐答案
您可以添加到您的模型中.
You can add to your model.
public static function getTableName()
{
return (new self())->getTable();
}
然后你就可以用Something::getTableName()
这篇关于如何从 Eloquent 模型静态获取表名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!