相关疑难解决方法(0)

如何在4个表中使用Laravel的hasManyThrough

我有4个表,结构和流程如下:

User
Accounts
Contacts
Orders
Run Code Online (Sandbox Code Playgroud)

关系如下:

$用户>的hasMany( '账户') - >的hasMany( '接触') - >的hasMany( '订单');

/** User Model **/
class User extend Eloquent {
    public function accounts(){
        return $this->hasMany('Accounts');
    }

    public function contacts(){
        return $this->hasManyThrough('Contact', 'Account', 'owner_id');
    }

    //how do I get this?
    public function orders(){

    }
}

/** Account Model */
class Account extends Eloquent {
    public function $user(){
        return $this->belongsTo('User');
    }
    public function contacts(){
        return $this->hasMany('Contact');
    }
}

/** Contact Model **/
class Contact extends Eloquent {
    public function …
Run Code Online (Sandbox Code Playgroud)

php laravel laravel-5 laravel-5.2

5
推荐指数
3
解决办法
3648
查看次数

标签 统计

laravel ×1

laravel-5 ×1

laravel-5.2 ×1

php ×1