Update source into github
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Repositories\Setting\SettingRepositoryInterface;
|
||||
use Exception;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Http\Facade\SignRSA;
|
||||
|
||||
class SettingController extends Controller
|
||||
{
|
||||
|
||||
public function __construct(
|
||||
public SettingRepositoryInterface $settingRepository
|
||||
)
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$title = 'General Setting';
|
||||
|
||||
return view('admin.setting', compact('title'));
|
||||
}
|
||||
|
||||
public function smtp()
|
||||
{
|
||||
$title = 'SMTP Setting';
|
||||
|
||||
return view('admin.smtp', compact('title'));
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
foreach ($request->except(['_token', '_method']) as $key => $value) {
|
||||
if (!empty($key)) {
|
||||
if (is_array($value)) {
|
||||
$value = json_encode($value);
|
||||
}
|
||||
|
||||
// Nếu key là smtp -> kiểm tra và mã hoá password nếu có
|
||||
if ($key === 'smtp') {
|
||||
$decoded = is_array($value) ? $value : json_decode($value, true);
|
||||
|
||||
if (isset($decoded['password']) && !empty($decoded['password'])) {
|
||||
$decoded['password'] = SignRSA::EncryptFunc($decoded['password']);
|
||||
}
|
||||
|
||||
$value = json_encode($decoded);
|
||||
}
|
||||
|
||||
$this->settingRepository->updateOrCreateByKey($key, [
|
||||
'key' => $key,
|
||||
'value' => $value
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
} catch (Exception $error) {
|
||||
DB::rollBack();
|
||||
return back()->withErrors($error->getMessage());
|
||||
}
|
||||
|
||||
return back()->with('success', 'Updated Successfully');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user