diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php index 1cc5f9c..a8ee736 100644 --- a/app/Http/Controllers/SettingsController.php +++ b/app/Http/Controllers/SettingsController.php @@ -5,7 +5,7 @@ namespace App\Http\Controllers; use App\Models\Settings; use Illuminate\Http\Request; use Illuminate\Support\Facades\Cache; -use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Storage; class SettingsController extends Controller { @@ -32,28 +32,43 @@ class SettingsController extends Controller 'recently_added_amount' => 'required|integer|between:0,12', 'currency' => 'required|string|size:3', 'sort_on' => 'required|integer|between:1,10', + 'favicon' => 'sometimes|nullable|mimes:ico,jpg,png|max:40', ]); - $update = DB::table('settings') - ->where('id', 1) - ->update([ - 'dark_mode' => $request->dark_mode, - 'show_versions_footer' => $request->show_versions_footer, - 'show_servers_public' => $request->show_servers_public, - 'show_server_value_ip' => $request->show_server_value_ip, - 'show_server_value_hostname' => $request->show_server_value_hostname, - 'show_server_value_provider' => $request->show_server_value_provider, - 'show_server_value_location' => $request->show_server_value_location, - 'show_server_value_price' => $request->show_server_value_price, - 'show_server_value_yabs' => $request->show_server_value_yabs, - 'save_yabs_as_txt' => $request->save_yabs_as_txt, - 'default_currency' => $request->default_currency, - 'default_server_os' => $request->default_server_os, - 'due_soon_amount' => $request->due_soon_amount, - 'recently_added_amount' => $request->recently_added_amount, - 'dashboard_currency' => $request->currency, - 'sort_on' => $request->sort_on, - ]); + $settings = Settings::where('id', 1)->first(); + + if ($request->favicon) {//Has a favicon upload + + $file = $request->favicon; + $extension = $file->getClientOriginalExtension(); + $favicon_filename = "favicon.$extension"; + + if ($favicon_filename !== $settings->favicon && $settings->favicon !== 'favicon.ico') { + Storage::disk('public_uploads')->delete($settings->favicon);//Delete old favicon + } + + $file->storeAs("", $favicon_filename, "public_uploads");//Save into /public + } + + $do_update = $settings->update([ + 'dark_mode' => $request->dark_mode, + 'show_versions_footer' => $request->show_versions_footer, + 'show_servers_public' => $request->show_servers_public, + 'show_server_value_ip' => $request->show_server_value_ip, + 'show_server_value_hostname' => $request->show_server_value_hostname, + 'show_server_value_provider' => $request->show_server_value_provider, + 'show_server_value_location' => $request->show_server_value_location, + 'show_server_value_price' => $request->show_server_value_price, + 'show_server_value_yabs' => $request->show_server_value_yabs, + 'save_yabs_as_txt' => $request->save_yabs_as_txt, + 'default_currency' => $request->default_currency, + 'default_server_os' => $request->default_server_os, + 'due_soon_amount' => $request->due_soon_amount, + 'recently_added_amount' => $request->recently_added_amount, + 'dashboard_currency' => $request->currency, + 'sort_on' => $request->sort_on, + 'favicon' => $favicon_filename ?? $settings->favicon + ]); Cache::forget('due_soon');//Main page due_soon cache Cache::forget('recently_added');//Main page recently_added cache @@ -71,7 +86,7 @@ class SettingsController extends Controller Settings::setSettingsToSession(Settings::getSettings()); - if ($update){ + if ($do_update) { return redirect()->route('settings.index') ->with('success', 'Settings Updated Successfully.'); } diff --git a/app/Models/Settings.php b/app/Models/Settings.php index 35e853e..b4792e6 100644 --- a/app/Models/Settings.php +++ b/app/Models/Settings.php @@ -14,7 +14,7 @@ class Settings extends Model protected $table = 'settings'; - protected $fillable = ['id', 'show_versions_footer', 'show_servers_public']; + protected $fillable = ['id', 'show_versions_footer', 'show_servers_public', 'show_server_value_ip', 'show_server_value_hostname', 'show_server_value_provider', 'show_server_value_location', 'show_server_value_price', 'show_server_value_yabs', 'save_yabs_as_txt', 'default_currency', 'default_server_os', 'due_soon_amount', 'recently_added_amount', 'dark_mode', 'dashboard_currency', 'sort_on', 'favicon']; public static function getSettings() { @@ -42,6 +42,7 @@ class Settings extends Model Session::put('recently_added_amount', $settings->recently_added_amount ?? 6); Session::put('dashboard_currency', $settings->dashboard_currency ?? 'USD'); Session::put('sort_on', $settings->sort_on ?? 1); + Session::put('favicon', $settings->favicon ?? 'favicon.ico'); Session::save(); } diff --git a/config/filesystems.php b/config/filesystems.php index 10c9d9b..df03435 100644 --- a/config/filesystems.php +++ b/config/filesystems.php @@ -42,6 +42,11 @@ return [ 'visibility' => 'public', ], + 'public_uploads' => [ + 'driver' => 'local', + 'root' => public_path(), + ], + 's3' => [ 'driver' => 's3', 'key' => env('AWS_ACCESS_KEY_ID'), diff --git a/database/migrations/2023_03_31_001352_add_favicon_to_settings_table.php b/database/migrations/2023_03_31_001352_add_favicon_to_settings_table.php new file mode 100644 index 0000000..addb731 --- /dev/null +++ b/database/migrations/2023_03_31_001352_add_favicon_to_settings_table.php @@ -0,0 +1,22 @@ +string('favicon')->after('sort_on')->default('favicon.ico'); + }); + } + + public function down(): void + { + Schema::table('settings', function (Blueprint $table) { + $table->dropColumn('favicon'); + }); + } +}; diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index d0bcb60..2b0eb0a 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -9,6 +9,7 @@ @endif @yield('title') - @if (config()->has('app.name')) {{ config('app.name') }} @else My idlers @endif + @if(Session::get('dark_mode')) diff --git a/resources/views/settings/index.blade.php b/resources/views/settings/index.blade.php index 87648c2..aca46ff 100644 --- a/resources/views/settings/index.blade.php +++ b/resources/views/settings/index.blade.php @@ -10,7 +10,7 @@ {{ route('/') }} Back to home -
+ @csrf @method('PUT')
@@ -70,11 +70,6 @@
-
-
- -
-

Only if Show servers to public is YES do these apply:

@@ -150,6 +145,12 @@
+
+
+ + +
+
Update settings