update([ 'company_name' => $request->company_name, 'company_email' => $request->company_email, 'company_phone' => $request->company_phone, 'notification_email' => $request->notification_email, 'company_address' => $request->company_address, 'default_currency_id' => $request->default_currency_id, 'default_currency_position' => $request->default_currency_position, 'footer_text' => $request->footer_text ]); cache()->forget('settings'); toast('Settings Updated!', 'info'); return redirect()->route('settings.index'); } public function updateSmtp(Request $request) { $toReplace = array( 'MAIL_MAILER='.env('MAIL_HOST'), 'MAIL_HOST="'.env('MAIL_HOST').'"', 'MAIL_PORT='.env('MAIL_PORT'), 'MAIL_FROM_ADDRESS="'.env('MAIL_FROM_ADDRESS').'"', 'MAIL_FROM_NAME="'.env('MAIL_FROM_NAME').'"', 'MAIL_USERNAME="'.env('MAIL_USERNAME').'"', 'MAIL_PASSWORD="'.env('MAIL_PASSWORD').'"', 'MAIL_ENCRYPTION="'.env('MAIL_ENCRYPTION').'"' ); $replaceWith = array( 'MAIL_MAILER='.$request->mail_mailer, 'MAIL_HOST="'.$request->mail_host.'"', 'MAIL_PORT='.$request->mail_port, 'MAIL_FROM_ADDRESS="'.$request->mail_from_address.'"', 'MAIL_FROM_NAME="'.$request->mail_from_name.'"', 'MAIL_USERNAME="'.$request->mail_username.'"', 'MAIL_PASSWORD="'.$request->mail_password.'"', 'MAIL_ENCRYPTION="'.$request->mail_encryption.'"'); try { file_put_contents(base_path('.env'), str_replace($toReplace, $replaceWith, file_get_contents(base_path('.env')))); Artisan::call('cache:clear'); toast('Mail Settings Updated!', 'info'); } catch (\Exception $exception) { Log::error($exception); session()->flash('settings_smtp_message', 'Something Went Wrong!'); } return redirect()->route('settings.index'); } }