Completed
Push — master ( 777c6c...1a5a10 )
by Mohamed
01:22
created

Setting::getTypeAttribute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Microboard\Models;
4
5
use Illuminate\Database\Eloquent\Builder;
6
use Illuminate\Database\Eloquent\Model;
7
use Spatie\MediaLibrary\HasMedia;
8
use Spatie\MediaLibrary\InteractsWithMedia;
9
10
class Setting extends Model implements HasMedia
0 ignored issues
show
Bug introduced by
There is at least one abstract method in this class. Maybe declare it as abstract, or implement the remaining methods: addMedia, addMediaConversion, clearMediaCollection, clearMediaCollectionExcept, copyMedia, getMedia, hasMedia, loadMedia, media, registerAllMediaConversions, registerMediaCollections, registerMediaConversions, shouldDeletePreservingMedia
Loading history...
11
{
12
    use InteractsWithMedia;
13
14
    /**
15
     * The attributes that are mass assignable.
16
     *
17
     * @var array
18
     */
19
    protected $fillable = [
20
        'group', 'key', 'title', 'value', 'type', 'options'
21
    ];
22
23
    /**
24
     * The attributes that should be cast.
25
     *
26
     * @var array
27
     */
28
    protected $casts = [
29
        'options' => 'array'
30
    ];
31
32
    /**
33
     * Return the value for the given key.
34
     *
35
     * @param string $delimiter
36
     * @param string $default
37
     * @return string|null
38
     */
39
    public static function getValueFor($delimiter, $default = '')
40
    {
41
        $key = explode('.', $delimiter);
42
        $group = $key[0];
43
44
        if (! isset($key[1])) {
45
            throw new \InvalidArgumentException("There is no key provided!");
46
        }
47
        $key = $key[1];
48
49
        return optional(self::where('key', $key)->where('group', $group)->first())->value ?? $default;
50
    }
51
}
52