2020-01-21 09:59:10 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
|
|
|
|
use Illuminate\Console\Command;
|
2022-06-13 10:55:39 +00:00
|
|
|
use Illuminate\Support\Facades\Config;
|
2020-01-21 09:59:10 +00:00
|
|
|
use Illuminate\Support\Facades\Mail;
|
|
|
|
|
2024-08-03 01:32:43 +00:00
|
|
|
use App\Mail\Test;
|
2022-06-13 10:55:39 +00:00
|
|
|
use App\Models\{Site,User};
|
2020-01-21 09:59:10 +00:00
|
|
|
|
2024-08-03 01:32:43 +00:00
|
|
|
class EmailTest extends Command
|
2020-01-21 09:59:10 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The name and signature of the console command.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2024-08-03 01:32:43 +00:00
|
|
|
protected $signature = 'test-email'
|
|
|
|
.' {--s|site : Site ID}'
|
|
|
|
.' {id : User ID}'
|
|
|
|
.' {email? : Alternative Email}';
|
2020-01-21 09:59:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The console command description.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $description = 'Send a test email';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the console command.
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
2024-08-03 01:32:43 +00:00
|
|
|
Config::set(
|
|
|
|
'site',
|
|
|
|
$this->option('site')
|
|
|
|
? Site::findOrFail($this->option('site'))
|
|
|
|
: Site::where('url',config('app.url'))->sole()
|
|
|
|
);
|
2022-06-13 10:55:39 +00:00
|
|
|
|
2020-01-21 09:59:10 +00:00
|
|
|
$uo = User::find($this->argument('id'));
|
|
|
|
|
2024-08-03 01:32:43 +00:00
|
|
|
$result = Mail::to($this->argument('email') ?? $uo->email)
|
|
|
|
->send(new Test($uo));
|
|
|
|
|
|
|
|
$this->info($result->getMessageId());
|
|
|
|
|
|
|
|
return self::SUCCESS;
|
2020-01-21 09:59:10 +00:00
|
|
|
}
|
|
|
|
}
|