如何在Laravel中返回数据库表名 [英] How to return database table name in Laravel
本文介绍了如何在Laravel中返回数据库表名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案
是 - 口才有一个 $ table
变量。有两种方式可以访问这个:
class yourModel extends Eloquent {
public static $ table =differentTable;
函数someFunction()
{
dd(yourModel :: $ table);
}
}
或
class yourModel extends Eloquent {
public function someFunction()
{
dd($ this-> table());
}
}
然后在你的代码
Route :: get('/',function(){
$ model = new yourModel();
dd($ model-> someFunction());
});
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 I've been unsuccessful calling it calling it from the model that I'm in.
解决方案
Yes - Eloquent has a $table
variable. There are two ways you can access this:
class yourModel extends Eloquent {
public static $table = "differentTable";
function someFunction()
{
dd(yourModel::$table);
}
}
or
class yourModel extends Eloquent {
public function someFunction()
{
dd($this->table());
}
}
then in your code
Route::get('/', function () {
$model = new yourModel();
dd($model->someFunction());
});
这篇关于如何在Laravel中返回数据库表名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文