Using Eloquent hasManyThrough

0
    // Modelo Cliente
    public function plano()
    {
    return $this->hasManyThrough('App\Plano', 'App\Plano_cliente','cliente_id','id','plano_id');
     }

    //Modelo Plano
    public function cliente()
    {
    return $this->hasManyThrough('App\Cliente', 'App\Plano_cliente','plano_id','id','cliente_id');
     }
    // Modelo Plano_cliente
    protected function cliente(){
    return $this->belongsToMany('App\Cliente')->withPivot('cliente_id', 'id');
    }
        protected function plano(){
    return $this->belongsToMany('App\Plano')->withPivot('plano_id', 'id');
    }

These are the three models Customer - > customer-plan

When I ask:  Client :: with (flat) -> get ();

returns in the resultset all clients but only the foreground of each Can have multiple plans each client

    
asked by anonymous 05.04.2016 / 18:09

1 answer

1

Client Template

    public function plano()
    {
    return $this->belongsToMany('App\Plano', 'plano_cliente','cliente_id','plano_id');
    }

Plan template

     public function cliente()
    {
    return $this->belongsToMany('App\Cliente', 'plano_cliente','plano_id','cliente_id');
    }

Client-level template

    protected function cliente(){
    return $this->belongsToMany('App\Cliente');
    }
    protected function plano(){
    return $this->belongsToMany('App\Plano');
    }

So that's all right

    
05.04.2016 / 21:54