首页 > 解决方案 > 我如何在单一连接中调用 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

标签: laravellaravel-5crudbooster

解决方案


您可以通过使用 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


推荐阅读