From ae3d27aca8933a67eebdf7afdb0aa8be0b5c296d Mon Sep 17 00:00:00 2001 From: KodeStar Date: Sun, 4 Feb 2018 21:28:11 +0000 Subject: [PATCH] get background switching working --- app/Http/Controllers/ItemController.php | 1 + app/Http/Controllers/SettingsController.php | 21 +++++----- app/Providers/AppServiceProvider.php | 7 ++++ resources/views/app.blade.php | 2 +- resources/views/settings/create.blade.php | 0 resources/views/settings/edit.blade.php | 9 +++++ resources/views/settings/form.blade.php | 43 +++++++++++++++++++++ resources/views/settings/list.blade.php | 2 +- routes/web.php | 2 +- 9 files changed, 75 insertions(+), 12 deletions(-) delete mode 100644 resources/views/settings/create.blade.php create mode 100644 resources/views/settings/edit.blade.php create mode 100644 resources/views/settings/form.blade.php diff --git a/app/Http/Controllers/ItemController.php b/app/Http/Controllers/ItemController.php index f1abea6c..cf1ddcb7 100644 --- a/app/Http/Controllers/ItemController.php +++ b/app/Http/Controllers/ItemController.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Item; +use App\Setting; use App\SupportedApps\Nzbget; use Illuminate\Support\Facades\Storage; diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php index bb5cacad..ea280e9c 100644 --- a/app/Http/Controllers/SettingsController.php +++ b/app/Http/Controllers/SettingsController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers; +use Illuminate\Http\Request; use App\Setting; use App\SettingGroup; use App\Http\Controllers\Controller; @@ -47,7 +48,7 @@ class SettingsController extends Controller * * @return \Illuminate\Http\RedirectResponse */ - public function update($id) + public function update(Request $request, $id) { $setting = Setting::find($id); @@ -55,24 +56,26 @@ class SettingsController extends Controller $data = Setting::getInput(); if ($setting->type == 'image') { - if (!is_null($data->image) && $data->image->isValid()) { - $destinationPath = uploads_path().'/settings/'; - $extension = $data->image->getClientOriginalExtension(); - $fileName = rand(11111111, 99999999).'.'.$extension; - $data->image->move($destinationPath, $fileName); - $setting->value = $fileName; + + + if($request->hasFile('value')) { + $path = $request->file('value')->store('backgrounds'); + $setting->value = $path; } + + + } else { $setting->value = $data->value; } $setting->save(); - return redirect()->route('settings.list')->with([ + return redirect()->route('settings.index')->with([ 'success' => 'You have successfully edited this Setting!', ]); } else { - return redirect()->route('settings.list')->with([ + return redirect()->route('settings.index')->with([ 'error' => 'This Setting does not exist.', ]); } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 9fe0a5e4..17864c94 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -4,6 +4,7 @@ namespace App\Providers; use Illuminate\Support\ServiceProvider; use Artisan; +use App\Setting; class AppServiceProvider extends ServiceProvider { @@ -23,6 +24,12 @@ class AppServiceProvider extends ServiceProvider //Artisan::call('config:cache'); //Artisan::call('route:cache'); } + $alt_bg = ''; + if($bg_image = Setting::fetch('background_image')) { + $alt_bg = ' style="background-image: url('.asset('storage/'.$bg_image).')"'; + } + view()->share('alt_bg', $alt_bg); + } /** diff --git a/resources/views/app.blade.php b/resources/views/app.blade.php index a26262a3..f7eaea38 100644 --- a/resources/views/app.blade.php +++ b/resources/views/app.blade.php @@ -11,7 +11,7 @@ -
+