使用口才关系获取表名 [英] Getting table name using Eloquent Relationship

查看:68
本文介绍了使用口才关系获取表名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

class SampleELoq extends Model
{
    use SoftDeletes;

    public function conditionFields() {
       return $this->belongsToMany('App\EloquentModel\ConditionField');
    }
}

nameSpace是SampleELoq的名称空间

nameSpace is the name space of the SampleELoq

$Eloq = $nameSpace::find(1);

$table = with(new $nameSpace->conditionFields)->getTable();

print_r(Schema::getColumnListing($table));

如何获取conditionFields的表名?

How can i able to get the table name of the conditionFields?

推荐答案

要从conditionFields获取表,您需要返回关系模型,然后可以通过getTable方法获取表.这样的人

To get table from conditionFields you need return relation model, then you can get table by getTable method. Some like this

Model::first()->conditionFields()->getRelated()->getTable()

这篇关于使用口才关系获取表名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆