$userAchievements * @property-read Collection $users */ class Achievement extends Model { protected $fillable = [ 'name', 'internal_name', 'short_description', 'long_description', 'icon', 'progressive', 'difficulty_description', 'achievement_category_id', 'achievement_difficulty_id', 'threshold', ]; protected $casts = [ 'progressive' => 'boolean', 'threshold' => 'integer', ]; // --------------------------------------------------------------- // Relationships // --------------------------------------------------------------- public function category(): BelongsTo { return $this->belongsTo(AchievementCategory::class, 'achievement_category_id'); } public function difficulty(): BelongsTo { return $this->belongsTo(AchievementDifficulty::class, 'achievement_difficulty_id'); } public function userAchievements(): HasMany { return $this->hasMany(UserAchievement::class, 'achievement_id'); } /** Users who have unlocked (or are progressing toward) this achievement. */ public function users(): BelongsToMany { return $this->belongsToMany(User::class, 'user_achievements') ->withPivot('progress') ->withTimestamps(); } }