I have a form which you can see in Image 1:
This form is called requests, it is a form where requests for authorization are received to be able to repair certain medical equipment, after that request is received an authorization is issued to repair them (but that is another story).
Of course the medical equipment belongs to a hospital and each hospital has its own inventory of medical equipment.
If you see the application form, there are two "+" "-" "buttons, that" + "button when pressed shows me a modal window that would be image 2:
There you can see all the equipment that is part of the hospital.
Now, if you notice in the modal window there is a field "#" that is where the team ID is, it is designed so that when you press that link the hospital team that is in the modal window goes to the form of requests, as you can see in Image 3:
Now, what is happening in real life? It happens that a hospital, when a team is damaged, issues an entity that repairs a "service request" that has all the data that can be seen in the application form, but most importantly, that request has a list of the equipment that needs to be repaired.
That is, "a request can have one or many equipment to be repaired" and "one or many computers can be in one or many requests", since a computer can be repaired today and can be part of the 0001 application but it can be can hurt tomorrow and be part of the 0002 application.
So here is a pivot table or intercept table. The huge doubt that I have is that the table that you can see in image 3 will be increasing as long as the same center asks in the same request to repair equipment that is of the same type, that is to say, a center can send 3 equipment to repair RX, is the same type, that is, RX machines.
Additional I show you:
Database diagram, in red you will see the pivot table:
Model named Team:
namespace dgmtm;
use Illuminate\Database\Eloquent\Model;
class Equipo extends Model
{
protected $table = 'equipos';
public $timestamps = true;
protected $fillable = [
'centro_id',
'servicio_id',
'tipoequipo_id',
'marca_equipo',
'modelo_equipo',
'serial_equipo',
'bien_nacional',
'equipo_garantia',
'responsable_garantia',
'duracion_garantia',
'observaciones_equipo'
];
protected $guarded = ['id'];
public function centro()
{
return $this->belongsTo('dgmtm\Centro');
}
public function servicio()
{
return $this->belongsTo('dgmtm\Servicio');
}
public function solicitud()
{
return $this->belongsToMany('dgmtm\Solicitud');
}
public function tipoequipo()
{
return $this->belongsTo('dgmtm\TipoEquipo');
}
}
Model called Request:
namespace dgmtm;
use Illuminate\Database\Eloquent\Model;
class Solicitud extends Model
{
protected $table = 'solicitudes';
public $timestamps = true;
protected $fillable = [
'id',
'autorizacion_id',
'numero_solicitud',
'fecha_solicitud',
'centro_id',
'responsable_emision',
'jefe_servicio'
];
protected $guarded = [];
public function centro()
{
return $this->belongsTo('dgmtm\Centro');
}
public function autorizacion()
{
return $this->belongsTo('dgmtm\Autorizacion');
}
public function equipo()
{
return $this->belongsToMany('dgmtm\Equipo');
}
}
Finally, the model called EquipoSolicitud (here I still do not know how the relationships are represented in Eloquent, many to many it is not very clear to me):
namespace dgmtm;
use Illuminate\Database\Eloquent\Model;
/**
* Class EquipoSolicitud
*/
class EquipoSolicitud extends Model
{
protected $table = 'equipo_solicitud';
public $timestamps = true;
protected $fillable = [
'solicitud_id',
'equipo_id',
'falla_reportada'
];
protected $guarded = ['id'];
}
Todaaaassss that business rules are already working perfectly but now comes the issue of saving in the database.
How do I save the data in the table that is supposed to go to the intercepted table in my database?