Laravel 5 hasMany relationship on two columns

后端 未结 4 2106
南方客
南方客 2020-11-30 03:13

Is it possible to have a hasMany relationship on two columns?

My table has two columns, user_id and related_user_id.

I want my rela

4条回答
  •  一个人的身影
    2020-11-30 04:06

    Compoships adds support for multi-columns relationships in Laravel 5's Eloquent.

    It allows you to specify relationships using the following syntax:

    public function b()
    {
        return $this->hasMany('B', ['key1', 'key2'], ['key1', 'key2']);
    }
    

    where both columns have to match.

提交回复
热议问题