Skip to content

How to propely use badges system #67

Description

@StevyMarlino

I don't really understand how to implement the badge system in my project.

after creating the models using the php artisan gamify:badge command, what happens next? do I have to create my own badge records in the badge table?

and as I'm affecting that this user has just earned such and such a badge?

the documentation isn't clear on the badge system.

my gamify config

i have add the Gamify Trait to my user and migrate the table already

<?php

declare(strict_types=1);

return [

    // Model which will be having points, generally it will be User
    'payee_model' => App\Models\User::class,

    // Reputation model
    'reputation_model' => '\QCod\Gamify\Reputation',

    // Allow duplicate reputation points
    'allow_reputation_duplicate' => true,

    // Broadcast on private channel
    'broadcast_on_private_channel' => true,

    // Channel name prefix, user id will be suffixed
    'channel_name' => 'user.reputation.',

    // Badge model
    'badge_model' => \QCod\Gamify\Badge::class,

    // Where all badges icon stored
    'badge_icon_folder' => 'images/badges/',

    // Extention of badge icons
    'badge_icon_extension' => '.svg',

    // All the levels for badge
    'badge_levels' => [
        'beginner' => 1,
        'intermediate' => 2,
        'advanced' => 3,
    ],

    // Default level
    'badge_default_level' => 1,

];

Here is one of my Badge i have created with the given command

<?php

declare(strict_types=1);

namespace App\Gamify\Badges;

use QCod\Gamify\BadgeType;

final class NewComerBadge extends BadgeType
{
    protected string $icon = 'new_comer.svg';

    /**
     * Check is user qualifies for badge
     */
    public function qualifier($user): bool
    {
        return $user->created_at->diffInMonths(now()) < 6;
    }
    
    public function getName(): string
    {
        return __('badges.new_comer.title');
    }
    
    public function getDescription(): string
    {
        return __('badges.new_comer.description');
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions