Until now, only existing settings could be saved. No new records, only updates.
70 lines
1.8 KiB
PHP
70 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests;
|
|
use Illuminate\Support\Facades\App;
|
|
|
|
class Settings extends Controller
|
|
{
|
|
/**
|
|
* @var \App\Models\Settings
|
|
*/
|
|
protected $settings;
|
|
|
|
/**
|
|
* Settings constructor.
|
|
*
|
|
* @param \App\Models\Settings $settings
|
|
*/
|
|
public function __construct(\App\Models\Settings $settings)
|
|
{
|
|
$this->settings = $settings;
|
|
}
|
|
|
|
public function getOverview()
|
|
{
|
|
$sections = App::make('registerSettingsExtension')
|
|
->get();
|
|
$settings = $this->settings->getAll();
|
|
|
|
return view('admin.settings.overview', [
|
|
'formSections' => $sections,
|
|
'settings' => $settings
|
|
]);
|
|
}
|
|
|
|
public function saveSettings(Requests\SaveSettingsRequest $request)
|
|
{
|
|
$data = $request->all();
|
|
// remove CSRF token field
|
|
unset($data['_token']);
|
|
|
|
$settings = $this->settings->getAll();
|
|
$updated = 0;
|
|
foreach ($data as $key => $value) {
|
|
if (isset($settings->$key)) {
|
|
if ($settings->$key != $value) {
|
|
$updated++;
|
|
\App\Models\Settings::where('key', $key)
|
|
->update(['value' => $value]);
|
|
}
|
|
} else {
|
|
\App\Models\Settings::create(['key' => $key, 'value' => $value]);
|
|
$updated++;
|
|
}
|
|
}
|
|
|
|
if ($updated > 0) {
|
|
return redirect()
|
|
->route('settings.overview')
|
|
->with('success', trans('admin/settings.successfullySaved'));
|
|
} else {
|
|
return redirect()
|
|
->route('settings.overview')
|
|
->with('error', trans('admin/settings.nothingToSave'));
|
|
}
|
|
}
|
|
}
|