Changeset View
Changeset View
Standalone View
Standalone View
src/app/Traits/UserSettingsTrait.php
Show All 13 Lines | trait UserSettingsTrait | ||||
* | * | ||||
* ```php | * ```php | ||||
* $user = User::firstOrCreate(['email' => 'some@other.erg']); | * $user = User::firstOrCreate(['email' => 'some@other.erg']); | ||||
* $locale = $user->getSetting('locale'); | * $locale = $user->getSetting('locale'); | ||||
* ``` | * ``` | ||||
* | * | ||||
* @param string $key Lookup key | * @param string $key Lookup key | ||||
* | * | ||||
* @return string | * @return string|null | ||||
*/ | */ | ||||
public function getSetting(string $key) | public function getSetting(string $key) | ||||
{ | { | ||||
$settings = $this->getCache(); | $settings = $this->getCache(); | ||||
$value = array_get($settings, $key); | |||||
return ($value !== '') ? $value : null; | if (!array_key_exists($key, $settings)) { | ||||
return null; | |||||
} | |||||
$value = $settings[$key]; | |||||
return empty($value) ? null : $value; | |||||
} | } | ||||
/** | /** | ||||
* Create or update a setting. | * Create or update a setting. | ||||
* | * | ||||
* Example Usage: | * Example Usage: | ||||
* | * | ||||
* ```php | * ```php | ||||
▲ Show 20 Lines • Show All 77 Lines • Show Last 20 Lines |