mirror of
				https://github.com/cp6/my-idlers.git
				synced 2025-10-31 06:19:09 +00:00 
			
		
		
		
	Added ability to upload own favicon
Must be either .ico, .jpg or .png format and under 40KB Upload is done in /settings Also removed save YABS to text input in settings form
This commit is contained in:
		
							parent
							
								
									f619f34081
								
							
						
					
					
						commit
						8a6748f1b0
					
				
					 6 changed files with 74 additions and 29 deletions
				
			
		|  | @ -5,7 +5,7 @@ namespace App\Http\Controllers; | ||||||
| use App\Models\Settings; | 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\Storage; | ||||||
| 
 | 
 | ||||||
| class SettingsController extends Controller | class SettingsController extends Controller | ||||||
| { | { | ||||||
|  | @ -32,11 +32,25 @@ class SettingsController extends Controller | ||||||
|             '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', | ||||||
|  |             'favicon' => 'sometimes|nullable|mimes:ico,jpg,png|max:40', | ||||||
|         ]); |         ]); | ||||||
| 
 | 
 | ||||||
|        $update =  DB::table('settings') |         $settings = Settings::where('id', 1)->first(); | ||||||
|             ->where('id', 1) | 
 | ||||||
|             ->update([ |         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, |             'dark_mode' => $request->dark_mode, | ||||||
|             'show_versions_footer' => $request->show_versions_footer, |             'show_versions_footer' => $request->show_versions_footer, | ||||||
|             'show_servers_public' => $request->show_servers_public, |             'show_servers_public' => $request->show_servers_public, | ||||||
|  | @ -53,6 +67,7 @@ class SettingsController extends Controller | ||||||
|             'recently_added_amount' => $request->recently_added_amount, |             'recently_added_amount' => $request->recently_added_amount, | ||||||
|             'dashboard_currency' => $request->currency, |             'dashboard_currency' => $request->currency, | ||||||
|             'sort_on' => $request->sort_on, |             'sort_on' => $request->sort_on, | ||||||
|  |             'favicon' => $favicon_filename ?? $settings->favicon | ||||||
|         ]); |         ]); | ||||||
| 
 | 
 | ||||||
|         Cache::forget('due_soon');//Main page due_soon cache
 |         Cache::forget('due_soon');//Main page due_soon cache
 | ||||||
|  | @ -71,7 +86,7 @@ class SettingsController extends Controller | ||||||
| 
 | 
 | ||||||
|         Settings::setSettingsToSession(Settings::getSettings()); |         Settings::setSettingsToSession(Settings::getSettings()); | ||||||
| 
 | 
 | ||||||
|         if ($update){ |         if ($do_update) { | ||||||
|             return redirect()->route('settings.index') |             return redirect()->route('settings.index') | ||||||
|                 ->with('success', 'Settings Updated Successfully.'); |                 ->with('success', 'Settings Updated Successfully.'); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  | @ -14,7 +14,7 @@ class Settings extends Model | ||||||
| 
 | 
 | ||||||
|     protected $table = 'settings'; |     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() |     public static function getSettings() | ||||||
|     { |     { | ||||||
|  | @ -42,6 +42,7 @@ class Settings extends Model | ||||||
|         Session::put('recently_added_amount', $settings->recently_added_amount ?? 6); |         Session::put('recently_added_amount', $settings->recently_added_amount ?? 6); | ||||||
|         Session::put('dashboard_currency', $settings->dashboard_currency ?? 'USD'); |         Session::put('dashboard_currency', $settings->dashboard_currency ?? 'USD'); | ||||||
|         Session::put('sort_on', $settings->sort_on ?? 1); |         Session::put('sort_on', $settings->sort_on ?? 1); | ||||||
|  |         Session::put('favicon', $settings->favicon ?? 'favicon.ico'); | ||||||
|         Session::save(); |         Session::save(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -42,6 +42,11 @@ return [ | ||||||
|             'visibility' => 'public', |             'visibility' => 'public', | ||||||
|         ], |         ], | ||||||
| 
 | 
 | ||||||
|  |         'public_uploads' => [ | ||||||
|  |             'driver' => 'local', | ||||||
|  |             'root'   => public_path(), | ||||||
|  |         ], | ||||||
|  | 
 | ||||||
|         's3' => [ |         's3' => [ | ||||||
|             'driver' => 's3', |             'driver' => 's3', | ||||||
|             'key' => env('AWS_ACCESS_KEY_ID'), |             'key' => env('AWS_ACCESS_KEY_ID'), | ||||||
|  |  | ||||||
|  | @ -0,0 +1,22 @@ | ||||||
|  | <?php | ||||||
|  | 
 | ||||||
|  | use Illuminate\Database\Migrations\Migration; | ||||||
|  | use Illuminate\Database\Schema\Blueprint; | ||||||
|  | use Illuminate\Support\Facades\Schema; | ||||||
|  | 
 | ||||||
|  | return new class extends Migration | ||||||
|  | { | ||||||
|  |     public function up(): void | ||||||
|  |     { | ||||||
|  |         Schema::table('settings', function (Blueprint $table) { | ||||||
|  |             $table->string('favicon')->after('sort_on')->default('favicon.ico'); | ||||||
|  |         }); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public function down(): void | ||||||
|  |     { | ||||||
|  |         Schema::table('settings', function (Blueprint $table) { | ||||||
|  |             $table->dropColumn('favicon'); | ||||||
|  |         }); | ||||||
|  |     } | ||||||
|  | }; | ||||||
|  | @ -9,6 +9,7 @@ | ||||||
|     @endif |     @endif | ||||||
| 
 | 
 | ||||||
|     <title>@yield('title') - @if (config()->has('app.name')) {{ config('app.name') }} @else My idlers @endif</title> |     <title>@yield('title') - @if (config()->has('app.name')) {{ config('app.name') }} @else My idlers @endif</title> | ||||||
|  |     <link rel="icon" type="image" href="{{asset(Session::get('favicon') ?? 'favicon.ico')}}"/> | ||||||
| 
 | 
 | ||||||
|     @if(Session::get('dark_mode')) |     @if(Session::get('dark_mode')) | ||||||
|         <link rel="stylesheet" href="{{ asset('css/dark.css') }}"> |         <link rel="stylesheet" href="{{ asset('css/dark.css') }}"> | ||||||
|  |  | ||||||
|  | @ -10,7 +10,7 @@ | ||||||
|                 <x-slot name="href">{{ route('/') }}</x-slot> |                 <x-slot name="href">{{ route('/') }}</x-slot> | ||||||
|                 Back to home |                 Back to home | ||||||
|             </x-back-button> |             </x-back-button> | ||||||
|             <form action="{{ route('settings.update', 1) }}" method="POST"> |             <form action="{{ route('settings.update', 1) }}" method="POST" enctype="multipart/form-data"> | ||||||
|                 @csrf |                 @csrf | ||||||
|                 @method('PUT') |                 @method('PUT') | ||||||
|                 <div class="row mt-2"> |                 <div class="row mt-2"> | ||||||
|  | @ -70,11 +70,6 @@ | ||||||
|                         </x-currency-select> |                         </x-currency-select> | ||||||
|                     </div> |                     </div> | ||||||
|                 </div> |                 </div> | ||||||
|                 <div class="row mt-3"> |  | ||||||
|                     <div class="col-12 col-md-6 mb-3"> |  | ||||||
|                         <x-yes-no-select title="Save YABS input to txt" name="save_yabs_as_txt" value="{{ $setting->save_yabs_as_txt }}"></x-yes-no-select> |  | ||||||
|                     </div> |  | ||||||
|                 </div> |  | ||||||
|                 <p>Only if <i>Show servers to public</i> is <b>YES</b> do these apply:</p> |                 <p>Only if <i>Show servers to public</i> is <b>YES</b> do these apply:</p> | ||||||
|                 <div class="row mt-3"> |                 <div class="row mt-3"> | ||||||
|                     <div class="col-12 col-md-6 mb-3"> |                     <div class="col-12 col-md-6 mb-3"> | ||||||
|  | @ -150,6 +145,12 @@ | ||||||
|                         </div> |                         </div> | ||||||
|                     </div> |                     </div> | ||||||
|                 </div> |                 </div> | ||||||
|  |                 <div class="row mt-3"> | ||||||
|  |                     <div class="col-12 col-md-6 mb-3"> | ||||||
|  |                         <label class="form-label pe-2" for="chooseFile">Add custom favicon must be either .ico|.png|.jpg MAX 40KB</label> | ||||||
|  |                         <input type="file" name="favicon" class="form-control" id="favicon"> | ||||||
|  |                     </div> | ||||||
|  |                 </div> | ||||||
|                 <div class="row"> |                 <div class="row"> | ||||||
|                     <div class="col-12 col-lg-4"> |                     <div class="col-12 col-lg-4"> | ||||||
|                         <x-submit-button>Update settings</x-submit-button> |                         <x-submit-button>Update settings</x-submit-button> | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue