osb/app/Console/Commands/EmailTest.php

54 lines
998 B
PHP
Raw Normal View History

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;
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
class EmailTest extends Command
2020-01-21 09:59:10 +00:00
{
/**
* The name and signature of the console command.
*
* @var string
*/
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()
{
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'));
$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
}
}