Giter Club home page Giter Club logo

Comments (12)

swirlingskirts avatar swirlingskirts commented on June 15, 2024 1

Hi again @gabriel-simonetti ! I'd be happy to share some -- did you have any in particular in mind?

Here's something for my user profile view:

@if ($achievements->count() > 0)
      <div class="achievements" id="achievements">
        <h3>{{$user->name}}'s achievements</h3>
        @foreach($achievements as $achievement)
        <div class="achievement">
          <img
          src="{{ asset('img/badges/'.strtolower(str_replace(' ', '_', $achievement->details->name)). '.png') }}"
          title="{{$achievement->details->name}}" alt="{{$achievement->details->name}} achievement badge"
          >
        </div>
        @endforeach
      </div>
      @endif

from laravel-achievements.

HDVinnie avatar HDVinnie commented on June 15, 2024 1

I use this in my profile view

            <div class="well">
                <div class="row">
                    <div class="col-md-12 profile-footer">
                        {{ $user->username }} - {{ trans('user.recent-achievements') }}:
                        @foreach($user->unlockedAchievements() as $a)
                            <img src="/img/badges/{{ $a->details->name }}.png" data-toggle="tooltip" title=""
                                 height="50px" data-original-title="{{ $a->details->name }}">
                        @endforeach
                        <div class="col-xs-1 achievements"><i
                                    class="{{ config('other.font-awesome') }} fa-trophy text-success"></i><span>{{ $user->unlockedAchievements()->count() }}</span>
                        </div>
                    </div>
                </div>
            </div>

from laravel-achievements.

HDVinnie avatar HDVinnie commented on June 15, 2024 1

This is actual user achievements view

@section('content')
    <div class="container">
        <div class="row">
            <div class="col-md-8">
                <div class="panel panel-default">
                    <div class="panel-heading">{{ trans('user.unlocked-achievements') }}</div>
                    <div class="panel-body">
                        <br/>
                        <div class="table-responsive">
                            <table class="table table-borderless">
                                <thead>
                                <tr>
                                    <th>{{ trans('common.name') }}</th>
                                    <th>{{ trans('common.description') }}</th>
                                    <th>{{ trans('common.progress') }}</th>
                                </tr>
                                </thead>
                                <tbody>
                                @foreach($achievements as $item)
                                    <tr>
                                        <td><img src="/img/badges/{{ $item->details->name }}.png"
                                                 data-toggle="tooltip" title=""
                                                 data-original-title="{{ $item->details->name }}"></td>
                                        <td>{{ $item->details->description }}</td>
                                        @if($item->isUnlocked())
                                            <td><span class="label label-success">{{ trans('user.unlocked')
											}}</span></td> @else
                                            <td><span class="label label-warning">{{
											trans('common.progress') }}:
                                                    {{$item->points}}/{{$item->details->points}}</span></td>
                                        @endif
                                    </tr>
                                @endforeach
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-sm-4 text-center">
                <div class="text-green well well-sm">
                    <?php $unlocked = auth()->user()->unlockedAchievements()->count() ?>
                    <h3>
                        <strong>{{ trans('user.unlocked-achievements') }}:</strong>{{
					$unlocked }}
                    </h3>
                </div>
                <div class="text-red well well-sm">
                    <?php $lock = auth()->user()->lockedAchievements()->count() ?>
                    <h3>
                        <strong>{{ trans('user.locked-achievements') }}:</strong>{{ $lock
					}}
                    </h3>
                </div>
            </div>
            <div class="col-md-8">
                <div class="panel panel-default">
                    <div class="panel-heading">{{ trans('user.pending-achievements') }}</div>
                    <div class="panel-body">
                        <br/>
                        <div class="table-responsive">
                            <table class="table table-borderless">
                                <thead>
                                <tr>
                                    <th>{{ trans('common.name') }}</th>
                                    <th>{{ trans('common.description') }}</th>
                                    <th>{{ trans('common.progress') }}</th>
                                </tr>
                                </thead>
                                <tbody>
                                @foreach($pending as $p)
                                    <tr>
                                        <td><img src="/img/badges/{{ $p->details->name }}.png"
                                                 data-toggle="tooltip" title=""
                                                 data-original-title="{{ $p->details->name }}"></td>
                                        <td>{{ $p->details->description }}</td>
                                        <td><span class="label label-warning">{{
											trans('common.progress') }}:
                                                {{$p->points}}/{{$p->details->points}}</span></td>
                                    </tr>
                                @endforeach
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-md-8">
                <div class="panel panel-default">
                    <div class="panel-heading">{{ trans('user.locked-achievements') }}</div>
                    <div class="panel-body">
                        <br/>
                        <div class="table-responsive">
                            <table class="table table-borderless">
                                <thead>
                                <tr>
                                    <th>{{ trans('common.name') }}</th>
                                    <th>{{ trans('common.description') }}</th>
                                    <th>{{ trans('common.progress') }}</th>
                                </tr>
                                </thead>
                                <tbody>
                                @foreach($locked as $l)
                                    <tr>
                                        <td><img src="/img/badges/{{ $l->details->name }}.png"
                                                 data-toggle="tooltip" title=""
                                                 data-original-title="{{ $l->details->name }}"></td>
                                        <td>{{ $l->details->description }}</td>
                                        <td><span class="label label-danger">{{ trans('user.locked') }}</span></td>
                                    </tr>
                                @endforeach
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection

from laravel-achievements.

swirlingskirts avatar swirlingskirts commented on June 15, 2024 1

I have this same code in all my achievements:

public function whenUnlocked($progress)
    {
      $user = $progress->achiever;
      ActivityAlert::create([
        'user_id' => $user->id,
        'alertable_type' => get_class($progress),
        'alertable_id' => $progress->id,
        'icon' => 'trophy',
        'url' => route('user.profile', ['id'=> $user->username]).'#achievements',
        'activity' => 'Achievement unlocked! '. $progress->details->name
      ]);
    }

Of course activity alerts is a model I've set up for various kinds of notifications.

from laravel-achievements.

HDVinnie avatar HDVinnie commented on June 15, 2024 1

Im using the SWAL alert example you provided.

from laravel-achievements.

swirlingskirts avatar swirlingskirts commented on June 15, 2024

I just got started with this package today and had a fairly robust achievement system (about 40 achievements, although some are "chained") going in about an hour. The documentation was quite adequate and clear, and the examples were excellent and got me going with all the basics. I'm still expanding my system, so I'll keep commenting if I run into issues. :)

from laravel-achievements.

swirlingskirts avatar swirlingskirts commented on June 15, 2024

Okay, here's a minor typo:

use App\Achievements\Have1000GoldOnTheBag;

$user->setProgress(new Have100GoldOnTheBag(), $user->amountOfGoldOnTheBag);

I'm almost certain you mean IN the bag rather than on?

On to more important things -- one thing I recall that DID trip me up about the docs was calling $user->unlockedAchievements() got me an instance of AchievementProgress. It tripped me up pretty badly when I could not do things like $achievement->name or even $achievement->achievement_detail->name in my view. Eventually through reading the code I was able to figure out that you've called it detail(), and that $achievement->detail->name did just fine. I think it would be worth showing that as an example.

from laravel-achievements.

gabs-simon avatar gabs-simon commented on June 15, 2024

That's interesting. Do you thing unlockedAchievements() should return instances of AchievementDetail instead?

I believe that what the documentation is lacking most is a way to display unlocked achievements. I have an example in a parallel repo but I have not linked it here.

from laravel-achievements.

gabs-simon avatar gabs-simon commented on June 15, 2024

And thanks for your feedback! Please let me know if you run into more issues while using this package.

from laravel-achievements.

swirlingskirts avatar swirlingskirts commented on June 15, 2024

No, I think what it returns now is fine, I just think there should be an explicit example included showing how to access the details. Even just demoing {{ $achievement->detail->name }} once would be a helpful hint for newbies.

from laravel-achievements.

gabs-simon avatar gabs-simon commented on June 15, 2024

Hi @kgenly !

I'm currently preparing base templates to be used for teaching purposes. Are you able and would you be willing to share the templates you have created on your system?

from laravel-achievements.

gabs-simon avatar gabs-simon commented on June 15, 2024

Thank you @HDVinnie and @kgenly for sharing your templates!

Do you have an example on how you're alerting your users for new Unlocks and Progresses?

from laravel-achievements.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.