-3
I’m trying to do a CRUD with Eloquent Laravel in 2 tables with FK AND PK, but I’m not succeeding, already have the models just missing the CRUD function even, someone can help me?
This is model with FK:
class crud_consignado_acordo extends Model
{
protected $fillable = [
'cpf',
'valor',
'formaenvio',
'datavencimento',
'numerocontrato',
'id_consignado_registro',
'id'
];
protected $table = 'tb_consignado_acordo';
public function registro()
{
return $this->belongsTo(crud_consignado_registro::class, 'id_consignado_registro');
}
}
E esta com a PK:
class crud_consignado_registro extends Model
{
protected $fillable = [
'produto',
'datareg',
'nomeoperador',
'celula',
'usuariox',
'aspect',
'supervisor',
'hora',
'id'
];
protected $table = 'tb_consignado_registro_operador';
public function acordo()
{
return $this->hasMany(crud_consignado_acordo::class, 'id_consignado_registro');
}
}
The doubt is how to do the CRUD with Eloquent Laravel ORM in these tables.
Always post your code to help, what have you already done in PHP? What is the structure of your bank? Where you are having difficulty more exactly?
– Costamilam
I recommend you try to follow the convention of the Eloquent Models whenever possible, this facilitates the maintenance of the code by other programmers and still avoids having to go through much thing per parameter, because it automatically recognizes the things based on the convention.
– Dobrychtop