Hello, I'm trying to get the data of a 'client'
I have 3 Tables
|Cliente|Cliente_servicio|Servicios
In the client table, I have a client's data
In the Customer_Service table I have the IDcliente, IDservicio, Description
in the Service table only the ID and name of the service
My relationship I have it So of the model Client is like this
public function clienteservicio()
{
return $this->HasMany(Clienteservicio::class);
}
From the Customer_Service model
public function cliente()
{
return $this->belongsTo(Cliente::class,'cliente_id');
}
public function servicio()
{
return $this->belongsTo(Servicio::class,'servicio_id');
}
And finally Service
public function Clienteservicio()
{
return $this->belongsTo(Clienteservicio::class);
}
=> App\Cliente {#2925
id: 2,
nick: "test",
nombre: "kjsdjkfsjkd",
apellidoP: "jksjdjfksjkd",
apellidoM: "jksjdkfjsdjkf",
vive: "sdfjksdjkfjksd",
created_at: "2018-10-07 22:08:15",
updated_at: "2018-10-07 22:08:15",
Clienteservicio: Illuminate\Database\Eloquent\Collection {#2932
all: [
App\Clienteservicio {#2937
id: 1,
cliente_id: 2,
servicio_id: 1,
descripcion: "excelente",
created_at: null,
updated_at: null,
},
App\Clienteservicio {#2935
id: 2,
cliente_id: 2,
servicio_id: 2,
descripcion: "ok",
created_at: null,
updated_at: null,
},
],
},
}
so far this is how I do my query, I was testing with tinker. but I can not get that data more than I'm interested in.
$prueba = Cliente::With(['Clienteservicio'])
->where('nick','test')
->first();
my relationships may be wrong but I can not understand.