获取laravel5模型中的所有关系名称 [英] Get all relations name in laravel5 model

查看:104
本文介绍了获取laravel5模型中的所有关系名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有模型包含几个关系,例如:

I have model include of several relation for example like this:

public function NewsCategory()
{ 
   return $this->belongsTo("News\Model\NewsCategory");
}
public function NewsImage()
{ 
   return $this->belongsTo("News\Model\NewsImage");
}
public function NewsTag()
{ 
   return $this->belongsTo("News\Model\NewsTag");
}

关系会动态创建.
如何获得所有此类名称? 在此示例中,我想要
NewsCategory,NewsImage,NewsTag

and relations create dynamically.
How can I get all this class name? In this example I want
NewsCategory,NewsImage,NewsTag

推荐答案

$model_specific_method_name_array = array_diff(get_class_methods(<YourMOdel>), get_class_methods(<AnotherDummyEloquentModelWithoutAnyMethods>));

然后从数组中删除模型上的其他已知方法.

Then remove other known methods on your model from array.

这篇关于获取laravel5模型中的所有关系名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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