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 Client -> plano_client <- Plan
When I do the consultation: Client::with(plan)->get();
returns in the resultset all clients but only the foreground of each Each client can have several plans
Exact and remember that can user a ->has('plan') or a ->with('plan'), being the first will be in the object what has a plan and in the second all with the plans.
– Evert