Back

How to apply toastr notification when user get leveled up?


This question is about how to implement a live notification if the user gets leveled up. My leveling system consists of 100 levels, so every time a user levels up, a notification will pop up into their profile.

`` Controller

 while($user->curr_exp >= $user->exp_needed){
             if($user->level == 10 || $user->level == 15 || $user->level == 20)
               {
                  $user->reward_token += 1;
               }
                  $user->curr_exp -= $user->exp_needed;   
                  $user->prev_exp = $user->exp_needed;
               if($user->level <= 19){
                   $user->exp_needed = $user->prev_exp * 1.4;
               }
               elseif($user->level >= 20 && $user->level <= 39){
                   $user->exp_needed = $user->prev_exp * 1.1;
               }
               elseif($user->level >= 40 && $user->level <= 59){
                   $user->exp_needed = $user->prev_exp * 1.05;
               }
               elseif($user->level >= 60 && $user->level <= 79){
                   $user->exp_needed = $user->prev_exp * 1.04;
               }
               elseif($user->level >= 80 && $user->level <= 99){
                   $user->exp_needed = $user->prev_exp * 1.03;
               }
               elseif($user->level == 100){
                   $user->exp_needed = $user->exp_needed * 0;
               }
                   $user->level += 1;
                   $user->save();
               }

``

Edit: I have already added a toaster to my profile.blade.php here is the script:

`` ** Profile.blade.php script **

 $(document).ready(function(e){
  $.toast({
    text: 'You level up!',
    heading: 'Congratulations',
    icon: 'info',
    position: 'top-right',
    bgColor: '#d4af37',
    textColor: 'black'
});

``

I'm using laravel 5.4 on this one. I'm confused how to display a live notifications on the user's profile every time they leveled up.

Any ideas? Thank you

Luke Wright replied 1 week ago

Tremendous efforts go to evolve through to the notification salutes the way to define solutions definitely look forward to more levels updates or connect with official writers hub like custom dissertation writers packed knowledge deals.


Sign in to participate in this thread!



We'd like to thank these amazing companies for supporting us