I'm traying to fill a pivot table between two tables using Filament
equipos:
Schema::create('equipos', function (Blueprint $table) {
$table->id();
$table->string('nombre')->unique();
$table->timestamps();
});
jugadors
Schema::create('jugadors', function (Blueprint $table) {
$table->id();
$table->string('nombre');
$table->string('apellidos');
$table->string('email')->unique();
$table->timestamps();
});
equipo_jugador:
Schema::create('equipo_jugador', function (Blueprint $table) {
$table->foreignId('jugador_id')->references('id')->on('jugadors');
$table->foreignId('equipo_id')->references('id')->on('equipos');
}
I have the relationships
class Equipo extends Model
{
use HasFactory;
protected $fillable =['id','nombre', 'nombre_jugador_1' ,'nombre_jugador_2'];
public function jugador1()
{
return $this->belongsToMany(Jugador::class);
}
public function jugador2()
{
return $this->belongsToMany(Jugador::class);
}
}
class Jugador extends Model
{
use HasFactory;
protected $fillable=['id','nombre','apellidos','email'];
public function equipos()
{
return $this->belongsToMany(Equipo::class);
}
}
When i create a equipo i want to fill the pivot table
what is the best way to do this?
Thanks