Unverified Commit 0e4788e3 authored by Viral Solani's avatar Viral Solani Committed by GitHub

Merge pull request #81 from bvipul/vs_settings

Refactored Settings
parents fa36f1e7 344ada51
......@@ -14,13 +14,10 @@ use Illuminate\Http\Request;
*/
class SettingsController extends Controller
{
/**
* @var SettingsRepository
*/
protected $settings;
/**
* @param SettingsRepository $settings
* @param \App\Repositories\Backend\Settings\SettingsRepository $settings
*/
public function __construct(SettingsRepository $settings)
{
......@@ -28,8 +25,8 @@ class SettingsController extends Controller
}
/**
* @param Setting $setting
* @param ManageEmailTemplatesRequest $request
* @param \App\Models\Settings\Setting $setting
* @param \App\Http\Requests\Backend\Settings\ManageSettingsRequest $request
*
* @return mixed
*/
......@@ -40,16 +37,18 @@ class SettingsController extends Controller
}
/**
* @param Setting $setting
* @param UpdateEmailTemplatesRequest $request
* @param \App\Models\Settings\Setting $setting
* @param \App\Http\Requests\Backend\Settings\UpdateSettingsRequest $request
*
* @return mixed
*/
public function update(Setting $setting, UpdateSettingsRequest $request)
{
$this->settings->update($setting, $request->all());
$this->settings->update($setting, $request->except(['_token', '_method']));
return redirect()->route('admin.settings.edit', $setting->id)->withFlashSuccess(trans('alerts.backend.settings.updated'));
return redirect()
->route('admin.settings.edit', $setting->id)
->with('flash_success', trans('alerts.backend.settings.updated'));
}
/**
......
......@@ -27,25 +27,9 @@ class UpdateSettingsRequest extends Request
*/
public function rules()
{
$data = Setting::find(1);
$checkLogo = $data->logo;
$checkFavicon = $data->favicon;
if (!empty($checkLogo)) {
$logoValidation = 'image|dimensions:min_width=226,min_height=48';
} else {
$logoValidation = 'required|image|dimensions:min_width=226,min_height=48';
}
if (!empty($checkFavicon)) {
$faviconValidation = 'mimes:jpg,jpeg,png,ico|dimensions:width=16,height=16';
} else {
$faviconValidation = 'required|mimes:jpg,jpeg,png,ico|dimensions:width=16,height=16';
}
return [
'logo' => $logoValidation,
'favicon' => $faviconValidation,
'from_name' => 'required',
'from_email' => 'required',
'logo' => 'image|dimensions:min_width=226,min_height=48',
'favicon' => 'mimes:jpg,jpeg,png,ico|dimensions:width=16,height=16',
];
}
......@@ -58,11 +42,7 @@ class UpdateSettingsRequest extends Request
{
return [
'logo.dimensions' => 'Invalid logo - should be minimum 226*48',
'favicon.dimensions' => 'Invalid icon - should be 16*16',
'logo.required' => 'The logo field is required in seo settings.',
'favicon.required' => 'The favicon field is required in seo settings.',
'from_name.required' => 'The from name field is required in mail settings.',
'from_email.required' => 'The from email field is required in mail settings.',
'favicon.dimensions' => 'Invalid favicon - should be 16*16'
];
}
}
......@@ -18,19 +18,15 @@ class SettingsRepository extends BaseRepository
const MODEL = Setting::class;
/**
* @param Model $permission
* @param \App\Models\Settings\Setting $setting
* @param $input
*
* @throws GeneralException
* @throws \App\Exceptions\GeneralException
*
* return bool
*/
public function update(Model $setting, array $input)
public function update(Setting $setting, array $input)
{
// Unsetting method and token values from array
unset($input['_method']);
unset($input['_token']);
if (isset($input['logo'])) {
$image_upload = $this->uploadlogoimage($setting, $input['logo']);
$input['logo'] = $image_upload;
......@@ -41,13 +37,11 @@ class SettingsRepository extends BaseRepository
$input['favicon'] = $image_upload;
}
DB::transaction(function () use ($setting, $input) {
if ($setting->update($input)) {
return true;
}
throw new GeneralException(trans('exceptions.backend.settings.update_error'));
});
}
/*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment