Skip to content

Instantly share code, notes, and snippets.

@connor11528
Last active April 10, 2020 16:18
Show Gist options
  • Save connor11528/6ec976363d3b4adfb1ae318b1e530949 to your computer and use it in GitHub Desktop.
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
<?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);
});
}
}
@connor11528
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment