Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

SilvioDev's avatar

Update a relationship with eloquent

Hi.

I have 3 tables: boote (boats): id,name,... sportler (athletes):id,name,... boot_sportler : id,boot_id,sportler_id,position,...

In the Table boot_sportler is the relationship. On boat can have many athlets. I want to update a boat and want that the athlets will saved automaticly.

I have 3 classses:

class Sportler extends Eloquent {
    protected $table = 'sportler';
    public function bootsbesatzungen(){
        return $this->belongsToMany('Bootsbesatzungen');
    }

}

class Boote extends Eloquent {
    protected $table = 'boote';
    public function bootsbesatzung(){
        return $this->hasMany('Bootsbesatzungen','boot_id');
    }
}

class Bootsbesatzungen extends Eloquent {
    protected $table = 'boot_sportler';
    public function sportler(){
        return $this->belongsTo('Sportler','sportler_id');
    }
}

And i have a blade file with textboxes to enter athlete names, boat name,... how i should integrate the data in my form? And how is the method to update it? in the moment i do it manually, but i want this with eloquent.

Thanks

0 likes
0 replies

Please or to participate in this conversation.