Last active
April 10, 2020 16:18
-
-
Save connor11528/6ec976363d3b4adfb1ae318b1e530949 to your computer and use it in GitHub Desktop.
The artisan command to approve a candidate to join the Employbl network so that they can login and update their profile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//... | |
class ApproveCandidate extends Command | |
{ | |
/** | |
* The name and signature of the console command. | |
* | |
* @var string | |
*/ | |
protected $signature = 'approve:candidates | |
{--userIds= : comma separated list of user ids to approve}'; | |
/** | |
* The console command description. | |
* | |
* @var string | |
*/ | |
protected $description = 'Approve candidate by setting active=1 on users table and sending them a welcome email :)'; | |
/** | |
* Create a new command instance. | |
* | |
* @return void | |
*/ | |
public function __construct() | |
{ | |
parent::__construct(); | |
} | |
/** | |
* Execute the console command. | |
* | |
* @return mixed | |
*/ | |
public function handle() | |
{ | |
$userIds = explode(',', $this->option('userIds')); | |
$users = User::find($userIds); | |
if($users->isEmpty()){ | |
$this->error('No users found with any of those ids'); | |
return; | |
} | |
$users->each(function($user){ | |
$user->active = 1; | |
$user->save(); | |
Mail::to($user->email) | |
->send(new \App\Mail\ApproveCandidate($user)); | |
$this->info('Sent approval email to ' . $user->email); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Full tutorial here: https://employbl.com/blog/user-approval-laravel-artisan-welcome-email