2022-05-09 18:18:01 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
2022-05-10 13:42:11 +02:00
|
|
|
use App\Enums\SettingTypes;
|
|
|
|
|
use App\Http\Requests\Setting\UpdateRequest;
|
2022-05-09 18:18:01 +02:00
|
|
|
use App\Models\Setting;
|
|
|
|
|
|
|
|
|
|
class SettingController extends Controller
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Display a listing of the resource.
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function index()
|
|
|
|
|
{
|
|
|
|
|
$settings = Setting::all();
|
|
|
|
|
return \view('setting.index', \compact('settings'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Show the form for editing the specified resource.
|
|
|
|
|
*
|
2022-09-29 10:09:43 +02:00
|
|
|
* @param \App\Models\Setting $setting
|
2022-05-09 18:18:01 +02:00
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function edit(Setting $setting)
|
|
|
|
|
{
|
2022-05-10 13:42:11 +02:00
|
|
|
return \view('setting.edit', \compact('setting'));
|
2022-05-09 18:18:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
|
*
|
2022-09-29 10:09:43 +02:00
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
|
* @param \App\Models\Setting $setting
|
2022-05-09 18:18:01 +02:00
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
2022-05-10 13:42:11 +02:00
|
|
|
public function update(UpdateRequest $request, Setting $setting)
|
2022-05-09 18:18:01 +02:00
|
|
|
{
|
2022-05-10 13:42:11 +02:00
|
|
|
if ($setting->type->equals(SettingTypes::picture())) {
|
2022-09-29 10:09:43 +02:00
|
|
|
$file = $request->file('value');
|
|
|
|
|
$path = $file->storeAs(
|
2022-05-10 13:42:11 +02:00
|
|
|
'public/setting_img',
|
|
|
|
|
$setting->key . ".png"
|
|
|
|
|
);
|
|
|
|
|
$setting->value = \str_replace("public", "storage", $path);
|
|
|
|
|
} else {
|
|
|
|
|
$setting->value = $request->value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$setting->saveOrFail();
|
|
|
|
|
|
|
|
|
|
return redirect()->route('setting.edit', ['setting' => $setting])->with('status', __('La paramètre a été modifié.'));
|
2022-05-09 18:18:01 +02:00
|
|
|
}
|
|
|
|
|
}
|