lundi 28 janvier 2019

Access attributes of several different relationships in a CRUD Eloquent Laravel 5.7

I have a structure like this (Illustrative Template only) and I want to know how I can access the data of the whole relationship to do an insert / update in these tables with the data received from a form, being that I can give a select withLEFT JOIN in all these tables using a query withDB :: raw, but I want to know how to do this only with the eloquent methods. From process to file:

I do not have enough reputation to post the direct image here:
Diagram: https://imageshack.com/a/img924/8796/Cmw5xB.png

Where as you can see one Processo has only one solicitacao and contrariwise, one solicitacao may have N boxes and a box can be in N solicitacao, being that one box may have Narquivo.

My Model Processo would look like this:

public function processo_solicitacao (){
 return $this->belongTo(Solicitacao::class, 'id_solicitacao', 'solicitacao_id');
}  

My Model solicitacao like this:

public function processo (){
 return $this->hasOne(Processo::class);
}  

My Model box like this:

public function solicitacoes (){
 return $this->belongsToMany(Processo::class);
}
public function arquivos(){
 return $this->hasMany(Arquivo::class);
}

My Model arquivo like this:

public function solicitacoes (){
 return $this->belongsTo(Box::class, 'box_id', 'id_box');
}

Thanks in advance for your help!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire