gstt/laravel-achievements

Past Timestamps / Pass a Timestamp

droplister opened this issue · 2 comments

Is there a way to pass a timestamp to the achievements? I'm trying to add achievements to an existing site and would like to pass a timestamp, so the achievements are recorded as being earned when the old activity happened.

Is my best bet to use this hook and just update the achievement's unlocked_at afterwards?

    /*
     * Triggers whenever an Achiever unlocks this achievement
    */
    public function whenUnlocked($progress)
    {
        
    }

I ended up listening on the Unlock event and updating the timestamp then.

You need to set it without using the Eloquent model though because the save() method is overridden.

        // Timestamp
        DB::table('achievement_progress')
            ->where('id', '=', $event->progress->id)
            ->update(['unlocked_at' => TIMESTAMP]);