Skip to content

Instantly share code, notes, and snippets.

@mercuryseries
Last active December 14, 2016 06:27
Show Gist options
  • Save mercuryseries/5a12cac9856fd0d3c1a0c35cb77c818d to your computer and use it in GitHub Desktop.
Save mercuryseries/5a12cac9856fd0d3c1a0c35cb77c818d to your computer and use it in GitHub Desktop.
Unlock Newbies Badges
<?php
namespace App\Models\Enums;
class Badge
{
use HasEnums;
const GEEK = 'geek';
const TWITCHER = 'twitcher';
const NEWBIE = 'newbie';
const OLDER = 'older';
const VETERAN = 'veteran';
const ALUMNI = 'alumni';
const NETFLIXER = 'netflixer';
const FIRST_MUSHIBISHI = 'first-mushibishi';
const HUNGRY = 'hungry';
}
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
//
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
// Badges
$schedule->command('parlonscode:unlock-newbies-badges')->daily();
$schedule->command('parlonscode:unlock-olders-badges')->daily();
$schedule->command('parlonscode:unlock-veterans-badges')->daily();
// Reports
$schedule->command('parlonscode:daily-report')->dailyAt('23:55');
$schedule->command('parlonscode:weekly-report')->weekly();
$schedule->command('parlonscode:monthly-report')->monthly();
$schedule->command('parlonscode:yearly-report')->yearly();
// Database Cleaning
$schedule->command('parlonscode:clean-database')->monthly();
}
/**
* Register the Closure based commands for the application.
*
* @return void
*/
protected function commands()
{
load_routes( config('routes.console', []), 'console' );
}
}
<?php
namespace App\Console\Commands;
use App\Models\Enums\Badge as BadgeEnum;
use App\Models\User;
use Illuminate\Console\Command;
class UnlockNewbiesBadges extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'parlonscode:unlock-newbies-badges';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Unlock Newbies Badges';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
User::oneYearOld()->notYetNewbies()->chunk(100, function ($users) {
foreach($users as $user) {
$user->unlockBadge(BadgeEnum::NEWBIE);
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment