I pass the code of a relationship that I want to do, which would be the same as that of the users. A grandparent can have several applications and an application can belong to several grandparents:
The grandfather class would be
class Abuelo extends Model {
public function aplicaciones(){
return $this->belongsToMany(Aplicacion::class,'abuelos_aplicaciones','idAbuelo','idAplicacion')->withPivot('idAbuelo','idAplicacion');
}
}
The Application class is
protected $table='aplicaciones';
protected $primaryKey='idAplicacion';
public function abuelos(){
return $this->belongsToMany(Abuelo::class,'abuelos_aplicaciones','idAbuelo', 'idAplicacion')->withPivot('idAbuelo', 'idAplicacion');
}
The migration of the tabpla pivot is
public function up()
{
Schema::create('abuelos_aplicaciones', function (Blueprint $table) {
$table->increments('idAbueloAplicacion');
$table->integer('idAbuelo')->unsigned();
$table->integer('idAplicacion')->unsigned();
$table->boolean('activoAbueloAplicacion')->default(1);
$table->string('dosis')->nullable(true);
$table->string('detalleAplicacion')->nullable(true);
$table->date('fechaDeAgotado')->nullable(true);
$table->string('emailAvisoAgotado')->nullable(true);
$table->foreign('idAbuelo')->references('idAbuelo')->on('abuelos');
$table->foreign('idAplicacion')->references('idAplicacion')->on('aplicaciones');
$table->timestamps();
});
}
and I'm trying to recover for example the dose field of the pivot table so
$ grandparents = Grandparent :: with ('Room') - > with ('Mutual') -> find ($ id);
dd ($ grandparents);
That brings me a grandfather
but nowhere is there anything that says pivot
Grandpa {# 285 ▼ #table: "grandparents" #primaryKey: "grandpa"
fillable: array: 3 [▶] #guarded: [] #connection: "mysql" #keyType: "int" + incrementing: true #with: [] #withCount: [] #perPage: 15 + exists: true + wasRecentlyCreated: false #attributes: array: 18 [▶] #original: array: 18 [▶] #casts: [] #dates: [] #dateFormat: null #appends: [] #events: [] #observables: [ ] #relations: array: 2 [▼
"Habitacion" => Habitacion {#290 ▶}
"Mutual" => Mutual {#289 ▶} ] #touches: [] +timestamps: true #hidden: [] #visible: [] }
I hope you understand the code, but that's what happens, something is not working, I do not know what it is