fix: Add more verbose error when uploading background image (#1082)

This commit is contained in:
Attila Kerekes 2022-12-24 09:56:00 +00:00 committed by GitHub
parent df70dcc521
commit cd07d47445
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 20 deletions

View file

@ -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())]),
]);
}
}

View file

@ -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',