having the following tables-migrations in laravel:
Table person
Schema::create('personas', function (Blueprint $table) {
$table->increments('id');
$table->string("nombre");
$table->string("apellidom")->nullable();
$table->string("apellidop")->nullable();
$table->date("fecha_nacimiento")->nullable();
$table->string("ci")->nullable();
$table->enum("sexo",["masculino","femenino"])->defautl("masculino");
$table->string("celular")->nullable();
$table->string("direccion")->nullable();
$table->enum("tipo",["trabajador","paciente"])->default("trabajador");
$table->timestamps();
});
Table Charges
Schema::create('cargos', function (Blueprint $table) {
$table->increments('id');
$table->string("nombre");
$table->text("descripcion")->nullable();
$table->timestamps();
});
Intermediate table apersona-cargos :
Schema::create('persona_cargo', function (Blueprint $table) {
$table->integer("persona_id");
$table->integer("cargo_id");
$table->date("fecha");
$table->timestamps();
});
Being the relationship of many to many between Person and Charges .
$persona=new Persona($request->all());
$persona->save();
$cargo=new Cargo($request->all());
$cargo->save();
//aqui cual seria el codigo siguiente?
How do I insert the intermediate table persona_cargo ?, since it does not have a model.