diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php index 93691593..2adc7b2b 100644 --- a/app/Http/Controllers/SettingsController.php +++ b/app/Http/Controllers/SettingsController.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers; use App\Setting; use App\SettingGroup; +use Exception; use Illuminate\Contracts\View\View; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; @@ -53,7 +54,7 @@ class SettingsController extends Controller return redirect($route) ->with([ - 'error' => __('app.alert.error.not_exist'), + 'errors' => collect([__('app.alert.error.not_exist')]), ]); } } @@ -68,37 +69,44 @@ class SettingsController extends Controller { $setting = Setting::find($id); $user = $this->user(); + $route = route('settings.index', []); - if (! is_null($setting)) { - $data = Setting::getInput($request); + try { + if (is_null($setting)) { + throw new Exception('not_exists'); + } - $setting_value = null; - - if ($setting->type == 'image') { - if ($request->hasFile('value')) { - $path = $request->file('value')->store('backgrounds'); - $setting_value = $path; + if ($setting->type === 'image') { + if (!$request->hasFile('value')) { + throw new \Exception( + 'file_too_big' + ); } + + $path = $request->file('value')->store('backgrounds'); + + if ($path === null) { + throw new \Exception('file_not_stored'); + } + + $setting_value = $path; } else { + $data = Setting::getInput($request); $setting_value = $data->value; } $user->settings()->detach($setting->id); $user->settings()->save($setting, ['uservalue' => $setting_value]); - $route = route('settings.index', []); - return redirect($route) - ->with([ - 'success' => __('app.alert.success.setting_updated'), - ]); - } else { - $route = route('settings.index', []); - + ->with([ + 'success' => __('app.alert.success.setting_updated'), + ]); + } catch (Exception $e) { return redirect($route) - ->with([ - 'error' => __('app.alert.error.not_exist'), - ]); + ->with([ + 'errors' => collect([__('app.alert.error.'.$e->getMessage())]), + ]); } } diff --git a/resources/lang/en/app.php b/resources/lang/en/app.php index 9b38b4fe..7bb6df40 100644 --- a/resources/lang/en/app.php +++ b/resources/lang/en/app.php @@ -100,6 +100,8 @@ return array ( 'alert.success.tag_restored' => 'Tag restored successfully', 'alert.success.setting_updated' => 'You have successfully edited this setting', 'alert.error.not_exist' => 'This setting does not exist.', + 'alert.error.file_too_big' => 'File is too big.', + 'alert.error.file_not_stored' => 'File could not be stored.', 'alert.success.user_created' => 'User created successfully', 'alert.success.user_updated' => 'User updated successfully', 'alert.success.user_deleted' => 'User deleted successfully',