laravel - 我如何在单一连接中调用 3 个关系 @ $this->col CRUDBOOSTER
问题描述
我一直在尝试在此代码中单次加入建立 3 个关系:
$this->col[] = array("label"=>"Jabatan","name"=>"profil_id","join"=>"profils,jabatan_id","join"=>"jabatans,nama_jabatan");`
但这是行不通的,我唯一能做的就是像下面的代码一样在单一连接中建立 2 个关系:
$this->col[] = array("label"=>"Jabatan","name"=>"profil_id","join"=>"profils,jabatan_id");`
我可以做的输出:
我只想更改id列并显示jabatans表中 的nama_jabatan列
解决方案
您可以通过使用 laravel 关系来做到这一点,在您的模型中定义关系并调用它。
class Profils extends Authenticatable
{
public function jabatans()
{
return $this->hasOne('jabantasmodelname');
}
}
并称之为
$profile = Profils::find(1)->jabatans;
如需进一步了解,您可以查看 laravel 文档(https://laravel.com/docs/5.8/eloquent-relationships)
推荐阅读
- sql - 具有两个变化属性的 SQL 数据库结构
- c# - 在 Net Core 2.2 中积极验证后如何更新我自己的令牌过期时间?
- ios - TableView 不显示 Firebase 数据库中的数据
- php - PHP 从数据中提取所有可能的组合
- r - 如何知道 .ped 文件中每个 SNP 的不同类型的等位基因
- r - 有条件地在 Bookdown 中包含章节
- jmeter - 未正确生成分布式执行后 JMeter 5.1 中的 HTML 报告
- python-3.x - 如何在python中使用用户输入打印水平的数字行
- sql - 与 CTE(递归)不一致的结果
- sql - 使用条件计算表中的字段