UserVerifyEmail.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use Illuminate\Support\Str;
  5. use App\User;
  6. use Illuminate\Contracts\Console\PromptsForMissingInput;
  7. class UserVerifyEmail extends Command implements PromptsForMissingInput
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'user:verifyemail {username}';
  15. /**
  16. * The console command description.
  17. *
  18. * @var string
  19. */
  20. protected $description = 'Verify user email address';
  21. /**
  22. * Create a new command instance.
  23. *
  24. * @return void
  25. */
  26. public function __construct()
  27. {
  28. parent::__construct();
  29. }
  30. /**
  31. * Execute the console command.
  32. *
  33. * @return mixed
  34. */
  35. public function handle()
  36. {
  37. $username = $this->argument('username');
  38. $user = User::whereUsername($username)->first();
  39. if(!$user) {
  40. $this->error('Username not found');
  41. return;
  42. }
  43. if($user->email_verified_at) {
  44. $this->error('Email already verified ' . $user->email_verified_at->diffForHumans());
  45. return;
  46. }
  47. $user->email_verified_at = now();
  48. $user->save();
  49. $this->info('Successfully verified email address for ' . $user->username);
  50. }
  51. }