Issues (652)

app/Models/Widget.php (3 issues)

Labels
Severity
1
<?php
2
3
namespace Uccello\Core\Models;
4
5
use Uccello\Core\Database\Eloquent\Model;
6
7
class Widget extends Model
8
{
9
    /**
10
     * The table associated with the model.
11
     *
12
     * @var string
13
     */
14
    protected $table = 'widgets';
15
16
    /**
17
     * The attributes that should be casted to native types.
18
     *
19
     * @var array
20
     */
21
    protected $casts = [
22
        'data' => 'object',
23
    ];
24
25
    /**
26
     * The attributes that are mass assignable.
27
     *
28
     * @var array
29
     */
30
    protected $fillable = [
31
        'module_id',
32
        'label',
33
        'type',
34
        'class',
35
        'data',
36
    ];
37
38
    protected function initTablePrefix()
39
    {
40
        $this->tablePrefix = env('UCCELLO_TABLE_PREFIX', 'uccello_');
41
    }
42
43
    public function modules()
44
    {
45
        return $this->belongsToMany(Module::class, $this->tablePrefix.'modules_widgets')->withPivot('data');
46
    }
47
48
    /**
49
     * Returns full package name if it is defined, else returns null
50
     *
51
     * @return string|null
52
     */
53
    public function getPackageAttribute()
54
    {
55
        return $this->data->package ?? null;
0 ignored issues
show
The property data does not seem to exist on Uccello\Core\Models\Widget. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
56
    }
57
58
    /**
59
     * Returns package name to use for translation if defined, else returns an empty string
60
     *
61
     * @return string
62
     */
63
    public function getLanguagePackageAttribute()
64
    {
65
        $package = '';
66
67
        if ($this->data->package ?? false) {
0 ignored issues
show
The property data does not seem to exist on Uccello\Core\Models\Widget. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
68
            $packageParts = explode('/', $this->data->package);
69
            $package = $packageParts[count($packageParts)-1].'::';
70
        }
71
72
        return $package;
73
    }
74
75
    /**
76
     * Returns widget label for translation (with package name as prefix)
77
     *
78
     * @return string
79
     */
80
    public function getLabelForTranslationAttribute()
81
    {
82
        return $this->languagePackage.'widgets.'.$this->label; // We have to create a locale file called widgets.php
0 ignored issues
show
The property label does not seem to exist on Uccello\Core\Models\Widget. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
83
    }
84
}
85