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;
|
2023-08-23 10:38:11 +00:00
|
|
|
use App\Http\Requests\Bo\Settings\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;
|
2023-08-23 10:38:11 +00:00
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
use Illuminate\Support\Str;
|
2020-10-21 15:26:21 +02:00
|
|
|
|
|
|
|
|
class SettingsController extends Controller
|
|
|
|
|
{
|
2023-08-23 10:38:11 +00:00
|
|
|
/**
|
|
|
|
|
* Show the form for editing the specified resource.
|
|
|
|
|
*
|
|
|
|
|
* @param \App\Models\Settings $settings
|
|
|
|
|
* @return \Illuminate\Contracts\View\View
|
|
|
|
|
*/
|
|
|
|
|
public function edit(Settings $settings): \Illuminate\Contracts\View\View
|
2020-10-21 15:26:21 +02:00
|
|
|
{
|
2023-11-20 17:22:24 +01:00
|
|
|
return view('back::pages.settings.edit', [
|
2023-08-23 10:38:11 +00:00
|
|
|
'settingsModel' => $settings
|
|
|
|
|
]);
|
|
|
|
|
}
|
2020-11-23 11:22:42 +01:00
|
|
|
|
2023-08-23 10:38:11 +00:00
|
|
|
/**
|
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
|
*
|
|
|
|
|
* @param \App\Http\Requests\Bo\Settings\UpdateSettingsRequest $request
|
|
|
|
|
* @param \App\Models\Settings $settings
|
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
|
*/
|
|
|
|
|
public function update(UpdateSettingsRequest $request, Settings $settings): \Illuminate\Http\RedirectResponse
|
|
|
|
|
{
|
|
|
|
|
return DB::transaction(function () use ($request, $settings) {
|
|
|
|
|
$settings->fill($request->validated());
|
|
|
|
|
if ($settings->saveOrFail()) {
|
|
|
|
|
$settingsGlobal = app(Settings::class)
|
|
|
|
|
->select('name', 'company', 'analytics', 'start_date', 'end_date')->first();
|
|
|
|
|
Cache::put('settingsGlobal', $settingsGlobal);
|
|
|
|
|
return redirect()
|
|
|
|
|
->route('bo.settings.edit', $settings)
|
|
|
|
|
->with('success', trans(
|
|
|
|
|
'crud.messages.has_been_updated',
|
|
|
|
|
['model' => Str::singular(__('models.classes.settings'))]
|
|
|
|
|
));
|
2020-10-21 15:26:21 +02:00
|
|
|
}
|
2023-08-23 10:38:11 +00:00
|
|
|
return redirect()
|
|
|
|
|
->back()
|
|
|
|
|
->with('error', trans(
|
|
|
|
|
'crud.messages.cannot_be_updated',
|
|
|
|
|
['model' => Str::singular(__('models.classes.settings'))]
|
|
|
|
|
));
|
|
|
|
|
});
|
2020-10-21 15:26:21 +02:00
|
|
|
}
|
|
|
|
|
}
|