Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 8 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
Template | |
0.00% |
0 / 8 |
|
0.00% |
0 / 3 |
30 | |
0.00% |
0 / 1 |
category | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
user_shortcut | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getActionAttribute | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | |
3 | namespace App\Http\Models; |
4 | |
5 | use Illuminate\Database\Eloquent\Relations\BelongsTo; |
6 | use Illuminate\Database\Eloquent\Relations\HasOne; |
7 | |
8 | class Template extends Moloquent |
9 | { |
10 | protected $table = 'templates'; |
11 | |
12 | protected $fillable = [ |
13 | 'title', 'shortcut', 'first_line', 'text', 'html', |
14 | 'version', 'category_id', 'uploads', 'type', 'subcategory_lv1_id', 'subcategory_lv2_id', 'premium', 'unique_slug' |
15 | ]; |
16 | |
17 | public function category(): BelongsTo |
18 | { |
19 | return $this->belongsTo(TemplateCategory::class, 'category_id'); |
20 | } |
21 | |
22 | public function user_shortcut(): HasOne |
23 | { |
24 | return $this->hasOne(Shortcut::class); |
25 | } |
26 | |
27 | /** |
28 | * The accessors to append to the model's array form. |
29 | * |
30 | * @var array |
31 | */ |
32 | protected $appends = ['action']; |
33 | |
34 | /** |
35 | * Get the action atrribute for the template. |
36 | */ |
37 | public function getActionAttribute(): string |
38 | { |
39 | $shortcut = $this->user_shortcut; |
40 | |
41 | if (!$shortcut) { |
42 | return 'add'; |
43 | } |
44 | |
45 | if ($shortcut->template_version !== $this->version) { |
46 | return 'update'; |
47 | } |
48 | return 'reset'; |
49 | } |
50 | } |