FEATURE: add saving settings

This commit is contained in:
Michal Kváček
2016-03-14 00:46:09 +01:00
parent 603e989b1e
commit 0313a1239f
10 changed files with 222 additions and 3 deletions
+60
View File
@@ -0,0 +1,60 @@
<?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 ($settings->$key != $value) {
$updated ++;
\App\Models\Settings::where('key', $key)->update(['value' => $value]);
}
}
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'));
}
}
}
+18
View File
@@ -0,0 +1,18 @@
<?php
namespace App\Http\Requests;
class SaveSettingsRequest extends Request
{
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'pageName' => 'required',
];
}
}
+9 -2
View File
@@ -58,8 +58,8 @@ Route::group([
Route::post('templates/copy', 'CopyTemplate@createCopy')
->name('templates.postCopy');
// Route::get('templates/new/{pathId}', 'TemplateOverview@getPath')
// ->name('templates.new');
// Route::get('templates/new/{pathId}', 'TemplateOverview@getPath')
// ->name('templates.new');
Route::get('templates/edit/{id}', 'EditTemplate@getEdit')
->name('templates.edit');
@@ -209,6 +209,13 @@ Route::group([
Route::post('upload/image', 'UploadFile@postImage')
->name('upload.postImage');
// form with settings
Route::get('settings', 'Settings@getOverview')
->name('settings.overview');
Route::post('settings', 'Settings@saveSettings')
->name('settings.save');
// custom fields
// ------------------------------