src/Traits/Preferenceable.php
public function pref($key, $value = null, $type = 'string')
    {
        if (isset($value)) {
            $this->preferences()->updateOrCreate(['key' => $key], ['value' => $this->cast($value, $type),
                                                                   'type'  => $type, ]);

            Cache::put("{$this->slug}.'/'.{$key}", $value, 60);
            return $value;
        }

        if($value = Cache::get("{$this->slug}.'/'.{$key}"))
        {
            return $value;
        }

        if ($pref = $this->preferences()->forKey($key)->first()) {
            $value = $pref->value();
            $type = $pref->type();
        } else {
            $default = Preference::getDefault($this, $key);
            $value = $default->value();
            $type = $default->type();
        }
        
        Cache::put("{$this->slug}.'/'.{$key}", $value, 60);
        return $this->cast($value, $type);
    }
public function pref($key, $value = null, $type = 'string')
    {
        if (isset($value)) {
            $this->preferences()->updateOrCreate(['key' => $key], ['value' => $this->cast($value, $type),
                                                                   'type'  => $type, ]);

            Cache::put("{$this->slug}.'/'.{$key}", $value, 60);
            return $value;
        }

        if($value = Cache::get("{$this->slug}.'/'.{$key}"))
        {
            return $value;
        }

        if ($pref = $this->preferences()->forKey($key)->first()) {
            $value = $pref->value();
            $type = $pref->type();
        } else {
            $default = Preference::getDefault($this, $key);
            $value = $default->value();
            $type = $default->type();
        }
        
        Cache::put("{$this->slug}.'/'.{$key}", $value, 60);
        return $this->cast($value, $type);
    }
public function pref ( $ key , $ value = null , $ type = 'string' ) { if ( isset ( $ value ) ) { $ this -> preferences ( ) -> updateOrCreate ( [ 'key' => $ key ] , [ 'value' => $ this -> cast ( $ value , $ type ) , 'type' => $ type , ] ) ; Cache :: put ( "{$this->slug}.'/'.{$key}" , $ value , 60 ) ; return $ value ; } if ( $ value = Cache :: get ( "{$this->slug}.'/'.{$key}" ) ) { return $ value ; } if ( $ pref = $ this -> preferences ( ) -> forKey ( $ key ) -> first ( ) ) { $ value = $ pref -> value ( ) ; $ type = $ pref -> type ( ) ; } else { $ default = Preference :: getDefault ( $ this , $ key ) ; $ value = $ default -> value ( ) ; $ type = $ default -> type ( ) ; } Cache :: put ( "{$this->slug}.'/'.{$key}" , $ value , 60 ) ; return $ this -> cast ( $ value , $ type ) ; }
Get or set preference value.

@param  mixed $key
@param  mixed $value
@param  string $type

@return mixed  Value.
Get or set preference value .