SettingsController update

Updated validation
Updated index view return
Update response from update
This commit is contained in:
cp6 2022-10-31 14:46:07 +11:00
parent ae5c541516
commit ac0cf82e8d

View File

@ -6,40 +6,35 @@ use App\Models\Settings;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Session;
class SettingsController extends Controller class SettingsController extends Controller
{ {
public function index() public function index()
{ {
$setting = DB::table('settings') return view('settings.index', ['setting' => Settings::where('id', 1)->first()]);
->where('id', '=', 1)
->get();
return view('settings.index', compact(['setting']));
} }
public function update(Request $request, Settings $settings) public function update(Request $request)
{ {
$request->validate([ $request->validate([
'dark_mode' => 'required|boolean', 'dark_mode' => 'required|integer|min:0|max:1',
'show_versions_footer' => 'required|boolean', 'show_versions_footer' => 'required|integer|min:0|max:1',
'show_server_value_ip' => 'required|boolean', 'show_server_value_ip' => 'required|integer|min:0|max:1',
'show_server_value_hostname' => 'required|boolean', 'show_server_value_hostname' => 'required|integer|min:0|max:1',
'show_server_value_provider' => 'required|boolean', 'show_server_value_provider' => 'required|integer|min:0|max:1',
'show_server_value_location' => 'required|boolean', 'show_server_value_location' => 'required|integer|min:0|max:1',
'show_server_value_price' => 'required|boolean', 'show_server_value_price' => 'required|integer|min:0|max:1',
'show_server_value_yabs' => 'required|boolean', 'show_server_value_yabs' => 'required|integer|min:0|max:1',
'save_yabs_as_txt' => 'required|boolean', 'save_yabs_as_txt' => 'required|integer|min:0|max:1',
'default_currency' => 'required', 'default_currency' => 'required|string|size:3',
'default_server_os' => 'required', 'default_server_os' => 'required|integer',
'due_soon_amount' => 'required|integer|between:0,12', 'due_soon_amount' => 'required|integer|between:0,12',
'recently_added_amount' => 'required|integer|between:0,12', 'recently_added_amount' => 'required|integer|between:0,12',
'currency' => 'required|string|size:3', 'currency' => 'required|string|size:3',
'sort_on' => 'required|integer|between:1,10', 'sort_on' => 'required|integer|between:1,10',
]); ]);
DB::table('settings') $update = DB::table('settings')
->where('id', 1) ->where('id', 1)
->update([ ->update([
'dark_mode' => $request->dark_mode, 'dark_mode' => $request->dark_mode,
@ -76,8 +71,13 @@ class SettingsController extends Controller
Settings::setSettingsToSession(Settings::getSettings()); Settings::setSettingsToSession(Settings::getSettings());
if ($update){
return redirect()->route('settings.index')
->with('success', 'Settings Updated Successfully.');
}
return redirect()->route('settings.index') return redirect()->route('settings.index')
->with('success', 'Settings Updated Successfully.'); ->with('error', 'Settings failed to update.');
} }
} }