Completed
Push — master ( 58b661...a53837 )
by Francesco
09:22
created

Question::getOptionsAttribute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
declare(strict_types = 1);
3
4
namespace App\Models;
5
6
use App\Models\Traits\EloquentGetTableName;
7
use Illuminate\Database\Eloquent\Model;
8
use Illuminate\Database\Eloquent\Relations\BelongsTo;
9
use Illuminate\Database\Eloquent\Relations\HasMany;
10
use Illuminate\Database\Eloquent\SoftDeletes;
11
12
class Question extends Model
13
{
14
15
    use SoftDeletes;
16
    use EloquentGetTableName;
17
18
    /**
19
     * The attributes that should be mutated to dates.
20
     *
21
     * @var array
22
     */
23
    protected $dates = ["deleted_at"];
24
    
25
    /**
26
     * The attributes that should be cast to native types.
27
     *
28
     * @var array
29
     */
30
    protected $casts = ["required" => "boolean"];
31
32
    /**
33
     * Get the possible answers of this question
34
     * @return HasMany
35
     */
36
    public function answers() : HasMany
37
    {
38
        return $this->hasMany("App\Models\Answer");
39
    }
40
41
    /**
42
     * Get the section of this question
43
     * @return BelongsTo
44
     */
45
    public function section() : BelongsTo
46
    {
47
        return $this->belongsTo("App\Models\Section");
48
    }
49
    
50
    public function getOptionsAttribute()
51
    {
52
        return json_decode($this->attributes["options"] ?? "");
53
    }
54
55
}
56