mirror of
				https://github.com/linuxserver/Heimdall.git
				synced 2025-10-31 21:17:44 +09:00 
			
		
		
		
	trying to get session settings to work
This commit is contained in:
		| @@ -80,7 +80,9 @@ class SettingsController extends Controller | ||||
|                 $setting_value = $data->value; | ||||
|             } | ||||
|  | ||||
|             $user->settings()->updateExistingPivot($setting->id, ['value' => $setting_value]); | ||||
|             $user->settings()->detach($setting->id); | ||||
|             $user->settings()->save($setting, ['uservalue' => $setting_value]); | ||||
|              | ||||
|             $route = route('settings.index', [], false); | ||||
|             return redirect($route)  | ||||
|             ->with([ | ||||
|   | ||||
| @@ -6,6 +6,8 @@ use Illuminate\Support\ServiceProvider; | ||||
| use Artisan; | ||||
| use Schema; | ||||
| use App\Setting; | ||||
| use App\User; | ||||
| use Session; | ||||
|  | ||||
| class AppServiceProvider extends ServiceProvider | ||||
| { | ||||
| @@ -32,7 +34,9 @@ class AppServiceProvider extends ServiceProvider | ||||
|         } | ||||
|         if(is_file(database_path('app.sqlite'))) { | ||||
|             if(Schema::hasTable('settings')) { | ||||
|                 if($bg_image = Setting::fetch('background_image')) { | ||||
|                 die("s: ".\Session::get('current_user')); | ||||
|                 //die("c: ".User::currentUser()); | ||||
|                 if($bg_image = Setting::_fetch('background_image', User::currentUser())) { | ||||
|                     $alt_bg = ' style="background-image: url(/storage/'.$bg_image.')"'; | ||||
|                 } | ||||
|  | ||||
|   | ||||
| @@ -157,10 +157,10 @@ class Setting extends Model | ||||
|      */ | ||||
|     public static function _fetch($key, $user=null) | ||||
|     { | ||||
|         $cachekey = ($user === null) ? $key : $key.'-'.$user->id; | ||||
|         if (Setting::cached($cachekey)) { | ||||
|             return Setting::$cache[$cachekey]; | ||||
|         } else { | ||||
|         #$cachekey = ($user === null) ? $key : $key.'-'.$user->id; | ||||
|         #if (Setting::cached($cachekey)) { | ||||
|         #    return Setting::$cache[$cachekey]; | ||||
|         #} else { | ||||
|             $find = self::where('key', '=', $key)->first(); | ||||
|  | ||||
|             if (!is_null($find)) { | ||||
| @@ -168,25 +168,33 @@ class Setting extends Model | ||||
|                     $value = $find->value; | ||||
|                 } else { // not system variable so use user specific value | ||||
|                     // check if user specified value has been set | ||||
|                     $usersetting = $user->settings->where('id', $find->id)->first(); | ||||
|                     //die(print_r($usersetting)); | ||||
|                     //print_r($user); | ||||
|                     $usersetting = $user->settings()->where('id', $find->id)->first(); | ||||
|                     //print_r($user->settings); | ||||
|                     //die(var_dump($usersetting)); | ||||
|                     //->pivot->value; | ||||
|                     //echo "user: ".$user->id." --- ".$usersettings; | ||||
|                     if(isset($usersetting) && !empty($usersetting)) { | ||||
|                         $value = $usersetting->pivot->value; | ||||
|                         $value = $usersetting->pivot->uservalue; | ||||
|                     } else { // if not get default from base setting | ||||
|                         //$user->settings()->save($find, ['value' => $find->value]); | ||||
|                         $user->settings()->updateExistingPivot($find->id, ['value' => $find->value]); | ||||
|                         #$has_setting = $user->settings()->where('id', $find->id)->exists(); | ||||
|                         #if($has_setting) { | ||||
|                         #    $user->settings()->updateExistingPivot($find->id, ['uservalue' => (string)$find->value]); | ||||
|                         #} else { | ||||
|                         #    $user->settings()->save($find, ['uservalue' => (string)$find->value]); | ||||
|                         #} | ||||
|                         $value = $find->value; | ||||
|                     } | ||||
|                      | ||||
|                 } | ||||
|                 Setting::add($cachekey, $value); | ||||
|                 #Setting::add($cachekey, $value); | ||||
|  | ||||
|                 return $value; | ||||
|             } else { | ||||
|                 return false; | ||||
|             } | ||||
|         } | ||||
|         #} | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -267,7 +275,7 @@ class Setting extends Model | ||||
|      */ | ||||
|     public function users() | ||||
|     { | ||||
|         return $this->belongsToMany('App\User')->withPivot('value'); | ||||
|         return $this->belongsToMany('App\User')->using('App\SettingUser')->withPivot('uservalue'); | ||||
|     } | ||||
|  | ||||
|     public static function user() | ||||
|   | ||||
							
								
								
									
										10
									
								
								app/SettingUser.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								app/SettingUser.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,10 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App; | ||||
|  | ||||
| use Illuminate\Database\Eloquent\Relations\Pivot; | ||||
|  | ||||
| class SettingUser extends Pivot | ||||
| { | ||||
|     // | ||||
| } | ||||
| @@ -40,7 +40,7 @@ class User extends Authenticatable | ||||
|      */ | ||||
|     public function settings() | ||||
|     { | ||||
|         return $this->belongsToMany('App\Setting')->withPivot('value'); | ||||
|         return $this->belongsToMany('App\Setting')->withPivot('uservalue'); | ||||
|     } | ||||
|  | ||||
|     public static function currentUser() | ||||
|   | ||||
		Reference in New Issue
	
	Block a user