Skip to content

Commit

Permalink
controller can be swapped now
Browse files Browse the repository at this point in the history
  • Loading branch information
saqueib committed Feb 11, 2019
1 parent d13ccd1 commit c20e575
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 42 deletions.
40 changes: 2 additions & 38 deletions src/Controllers/AppSettingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,10 @@

namespace QCod\AppSettings\Controllers;

use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use QCod\AppSettings\Setting\AppSettings;
use Illuminate\Foundation\Validation\ValidatesRequests;
use QCod\AppSettings\SavesSettings;

class AppSettingController extends Controller
{
use ValidatesRequests;

/**
* Display the settings page
*
* @return \Illuminate\View\View
*/
public function index()
{
$settingsUI = config('app_settings', []);
$settingViewName = config('app_settings.setting_page_view');

return view($settingViewName, compact('settingsUI'));
}

/**
* Save settings
*
* @param Request $request
* @param AppSettings $appSettings
* @return \Illuminate\Http\RedirectResponse
*/
public function store(Request $request, AppSettings $appSettings)
{
// validate the settings
$this->validate($request, $appSettings->getValidationRules());

// save settings
$appSettings->save($request);

return redirect(config('app_settings.url', '/'))
->with([
'status' => config('app_settings.submit_success_message', 'Settings Saved.')
]);
}
use SavesSettings;
}
46 changes: 46 additions & 0 deletions src/SavesSettings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace QCod\AppSettings;

use Illuminate\Http\Request;
use QCod\AppSettings\Setting\AppSettings;
use Illuminate\Foundation\Validation\ValidatesRequests;

trait SavesSettings
{
use ValidatesRequests;

/**
* Display the settings page
*
* @return \Illuminate\View\View
*/
public function index()
{
$settingsUI = config('app_settings', []);
$settingViewName = config('app_settings.setting_page_view');

return view($settingViewName, compact('settingsUI'));
}

/**
* Save settings
*
* @param Request $request
* @param AppSettings $appSettings
* @return \Illuminate\Http\RedirectResponse
*/
public function store(Request $request, AppSettings $appSettings)
{
// validate the settings
$this->validate($request, $appSettings->getValidationRules());

// save settings
$appSettings->save($request);

return redirect(config('app_settings.url', '/'))
->with([
'status' => config('app_settings.submit_success_message', 'Settings Saved.')
]);
}
}
6 changes: 2 additions & 4 deletions src/routes/web.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<?php

Route::group([
'namespace' => 'QCod\AppSettings\Controllers',
'middleware' => array_merge(['web'], config('app_settings.middleware', []))
], function () {
Route::get(config('app_settings.url'), 'AppSettingController@index');

Route::post(config('app_settings.url'), 'AppSettingController@store');
Route::get(config('app_settings.url'), config('app_settings.controller').'@index');
Route::post(config('app_settings.url'), config('app_settings.controller').'@store');
});

0 comments on commit c20e575

Please sign in to comment.