. */ namespace Poniverse\Ponyfm\Console\Commands; use Illuminate\Console\Command; use Poniverse\Ponyfm\Models\User; class RebuildArtists extends Command { /** * The name and signature of the console command. * * @var string */ protected $signature = 'rebuild:artists'; /** * The console command description. * * @var string */ protected $description = 'Recounts every user\'s tracks, ensuring that the artist directory isn\'t missing anyone.'; /** * Create a new command instance. * * @return void */ public function __construct() { parent::__construct(); } /** * Execute the console command. * * @return mixed */ public function handle() { foreach(User::with(['tracks' => function($query) { $query->published()->listed(); }])->get() as $user) { $user->track_count = $user->tracks->count(); $user->save(); $this->info('Updated user #'.$user->id.'!'); } } }