2020-10-21 15:26:21 +02:00
|
|
|
<?php
|
|
|
|
|
|
2022-01-10 14:02:25 +01:00
|
|
|
namespace App\Http\Controllers\Bo;
|
2020-10-21 15:26:21 +02:00
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
2022-03-10 16:35:58 +01:00
|
|
|
use App\Http\Requests\Bo\UpdateSettingsRequest;
|
2020-10-21 15:26:21 +02:00
|
|
|
use App\Models\Settings;
|
2020-11-20 15:18:31 +01:00
|
|
|
use Illuminate\Support\Facades\Cache;
|
2022-03-10 16:35:58 +01:00
|
|
|
use Illuminate\Support\Facades\Session;
|
2020-10-21 15:26:21 +02:00
|
|
|
|
|
|
|
|
class SettingsController extends Controller
|
|
|
|
|
{
|
2022-03-10 16:35:58 +01:00
|
|
|
/**
|
|
|
|
|
* Show edit settings page
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Contracts\View\View|\Illuminate\Contracts\View\Factory
|
|
|
|
|
*/
|
|
|
|
|
public function manage()
|
2020-10-21 15:26:21 +02:00
|
|
|
{
|
2022-01-11 10:25:23 +01:00
|
|
|
/** @var \App\Models\Settings $settings */
|
2022-01-07 19:00:30 +01:00
|
|
|
$settings = app(Settings::class);
|
2020-10-21 15:26:21 +02:00
|
|
|
|
2022-03-10 16:35:58 +01:00
|
|
|
return view('bo.settings.manage', compact('settings'));
|
|
|
|
|
}
|
2020-10-21 15:26:21 +02:00
|
|
|
|
2022-03-10 16:35:58 +01:00
|
|
|
/**
|
|
|
|
|
* Save settings
|
|
|
|
|
*
|
|
|
|
|
* @param UpdateSettingsRequest $request
|
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
|
*/
|
|
|
|
|
public function manageSubmit(UpdateSettingsRequest $request)
|
|
|
|
|
{
|
|
|
|
|
/** @var \App\Models\Settings $settings */
|
|
|
|
|
$settings = app(Settings::class);
|
2020-11-23 11:22:42 +01:00
|
|
|
|
2022-03-10 16:35:58 +01:00
|
|
|
$settings->fill($request->validated());
|
2020-10-21 15:26:21 +02:00
|
|
|
|
2022-03-10 16:35:58 +01:00
|
|
|
$redirectClose = $request->redirect_close;
|
|
|
|
|
// Check du lien de redirection après fermeture.
|
|
|
|
|
if (strpos($redirectClose, 'https://') === false && strpos($redirectClose, 'http://') === false) {
|
|
|
|
|
$redirectClose = 'https://' . $redirectClose;
|
|
|
|
|
}
|
|
|
|
|
$settings->redirect_close = $redirectClose;
|
2020-10-26 09:32:28 +01:00
|
|
|
|
2022-03-10 16:35:58 +01:00
|
|
|
if ($settings->saveOrFail()) {
|
2022-01-11 12:39:28 +01:00
|
|
|
$settingsGlobal = app(Settings::class)
|
2022-03-10 16:35:58 +01:00
|
|
|
->select('name', 'company', 'analytics', 'start_date', 'end_date')->first();
|
2020-11-20 15:18:31 +01:00
|
|
|
Cache::put('settingsGlobal', $settingsGlobal);
|
2022-03-10 16:35:58 +01:00
|
|
|
Session::flash('success', 'Modifications enregistrés !');
|
|
|
|
|
}
|
|
|
|
|
return \back();
|
2020-10-21 15:26:21 +02:00
|
|
|
}
|
|
|
|
|
}
|