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

AngelinCalu's avatar

Pivot Table with values (and values history)

So, basically I have 2 models\ 3 tables:

users
    id - integer

skills
   id - integer


skill_user (pivot table)
   skill_id - integer
   user_id - integer
   level   - float
   created_at 
   updated_at

and relationships:

  • in the User Model:
    /**
     * Return the skills associated to this user
     * @return [type] [description]
     */
    public function skills() {
        return $this->belongsToMany('App\Skill')
            ->withPivot('level')
            ->withTimestamps();
    }
  • in the Skills Model:
    /**
     * Return the users associated to this skill
     * @return [type] [description]
     */
    public function users() {
        return $this->belongsToMany('App\User')
            ->withPivot('level')
            ->withTimestamps();
    }

What I want is to track the skill level along the time. How would be the best way to achieve this? Can I have multiple attached values in the pivot table with different levels and different timestamps? Or should I create new model\table which should be updated every time the level will be updated ?

0 likes
0 replies

Please or to participate in this conversation.