Completed
Push — master ( bd4222...e5ba92 )
by Arjay
13:31
created

Extension::widget()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 5
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 8
rs 9.4285
1
<?php
2
3
namespace Yajra\CMS\Entities;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Support\Str;
7
use Yajra\CMS\Entities\Traits\HasParameters;
8
9
/**
10
 * @property string name
11
 * @property string type
12
 * @property string parameters
13
 * @property bool enabled
14
 * @property string manifest
15
 */
16
class Extension extends Model
17
{
18
    use HasParameters;
19
20
    /**
21
     * @var array
22
     */
23
    protected $fillable = ['name', 'type', 'enabled', 'parameters'];
24
25
    /**
26
     * Get a widget by name.
27
     *
28
     * @param string $name
29
     * @return $this
30
     */
31
    public static function widget($name)
32
    {
33
        $builder = static::query();
34
35
        return $builder->where('type', 'widget')
36
                       ->whereRaw('LOWER(name) = ?', [Str::lower($name)])
37
                       ->first();
38
    }
39
40
    /**
41
     * Get manifest attribute.
42
     *
43
     * @return object
44
     */
45
    public function getManifestAttribute()
46
    {
47
        return json_decode($this->attributes['manifest'], true);
48
    }
49
50
    /**
51
     * Get version.
52
     *
53
     * @return string
54
     */
55
    public function getVersionAttribute()
56
    {
57
        return $this->manifest['version'] ?? '0.0.0';
58
    }
59
60
    /**
61
     * Get description.
62
     *
63
     * @return string
64
     */
65
    public function getDescriptionAttribute()
66
    {
67
        return $this->manifest['description'] ?? 'No description';
68
    }
69
}
70