PhotoReport::getReasonCategoryAttribute()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace App\Models;
4
5
use Illuminate\Database\Eloquent\Builder;
6
7
/**
8
 * Class PhotoReport.
9
 */
10
class PhotoReport extends ChocolateyModel
11
{
12
    /**
13
     * Disable Timestamps.
14
     *
15
     * @var bool
16
     */
17
    public $timestamps = false;
18
19
    /**
20
     * The table associated with the model.
21
     *
22
     * @var string
23
     */
24
    protected $table = 'chocolatey_users_photos_reported';
25
26
    /**
27
     * Primary Key of the Table.
28
     *
29
     * @var string
30
     */
31
    protected $primaryKey = 'id';
32
33
    /**
34
     * The Appender(s) of the Model.
35
     *
36
     * @var array
37
     */
38
    protected $appends = ['reason_category'];
39
40
    /**
41
     * Store a new Photo Report.
42
     *
43
     * @param int $photoId
44
     * @param int $reasonId
45
     * @param int $reportedBy
46
     *
47
     * @return PhotoReport
48
     */
49
    public function store(int $photoId, int $reasonId, int $reportedBy): PhotoReport
50
    {
51
        $this->attributes['photo_id'] = $photoId;
52
        $this->attributes['reason_id'] = $reasonId;
53
        $this->attributes['reported_by'] = $reportedBy;
54
        $this->attributes['approved'] = 0;
55
        $this->timestamps = false;
56
57
        $this->save();
58
59
        return $this;
60
    }
61
62
    /**
63
     * Get the Report Category Content.
64
     *
65
     * @return Builder
66
     */
67
    public function getReasonCategoryAttribute()
68
    {
69
        return PhotoReportCategory::query()->where('report_category', $this->attributes['reason_id'])->first();
70
    }
71
}
72