Php 枢轴模型中的拉维关系

Php 枢轴模型中的拉维关系,php,mysql,laravel-5.2,Php,Mysql,Laravel 5.2,我有三个表,其中一个是pivot表(和pivot模型),并试图在pivot模型中创建belongsTo关系(pivot表中的外键),以便从其他一些表(具有主键)中获取相关名称。我想做的是通过下面的图片进行说明: 数据透视表为: 其他表格为: 这是一个枢轴模型: class MproductIngredient extends Model { public function qtyType() { return $this->belongsTo('App\TIngredientT

我有三个表,其中一个是pivot表(和pivot模型),并试图在pivot模型中创建belongsTo关系(pivot表中的外键),以便从其他一些表(具有主键)中获取相关名称。我想做的是通过下面的图片进行说明:
数据透视表为:
其他表格为:

这是一个枢轴模型:

class MproductIngredient extends Model {

public function qtyType() {
    return $this->belongsTo('App\TIngredientType','priQuantityTypeNo');
}
}
如何从其他表(具有主键)获取相关名称

我的代码是:

@foreach($prd->ingredients a $ingredient)
     "{!! $ingredient->pivot->priQuantityTypeNo !!}"
     @endforeach

请描述更多,据我所知,你可以做下面的关系

为了归属

哈松


关系是属于一个还是属于多个?基本上,我想在pivot模型中与其他表创建一个belongTo关系,请查看答案否,我不想得到这个,我想创建一个belongTo关系,从中我想从其他表中获取相关名称。谈论反向关系。
    public function qtyTypes()
    {
        return $this->belongsToMany('App\TIngredientType', 'pivot_table_name', 
          'main_table_id', 'TIngredientType_id');
    }
public function qtyType()
    {
        return $this->hasOne('App\TIngredientType');
    }