D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
forge
/
lactobokashi.com
/
app
/
Services
/
Filename :
MailService.php
back
Copy
<?php namespace App\Services; use App\Http\Requests\MailRequest; use Dipokhalder\EnvEditor\EnvEditor; use Exception; use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Log; use Smartisan\Settings\Facades\Settings; class MailService { public $envService; public function __construct(EnvEditor $envEditor) { $this->envService = $envEditor; } /** * @throws Exception */ public function list() { try { return Settings::group('mail')->all(); } catch (Exception $exception) { Log::info($exception->getMessage()); throw new Exception($exception->getMessage(), 422); } } /** * @throws Exception */ public function update(MailRequest $request) { try { Settings::group('mail')->set($request->validated()); $this->envService->addData([ 'MAIL_MAILER' => 'smtp', 'MAIL_HOST' => $request->mail_host, 'MAIL_PORT' => $request->mail_port, 'MAIL_USERNAME' => $request->mail_username, 'MAIL_PASSWORD' => $request->mail_password, 'MAIL_ENCRYPTION' => $request->mail_encryption, 'MAIL_FROM_ADDRESS' => $request->mail_from_email, 'MAIL_FROM_NAME' => $request->mail_from_name ]); Artisan::call('optimize:clear'); return $this->list(); } catch (Exception $exception) { Log::info($exception->getMessage()); throw new Exception($exception->getMessage(), 422); } } }