Passed
Push — feature/job-status-transitions ( 11bc93...554a22 )
by Tristan
06:45 queued 53s
created

HrAdvisor::department()   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
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace App\Models;
4
5
use Backpack\CRUD\app\Models\Traits\CrudTrait;
6
7
/**
8
 * Class HrAdvisor
9
 *
10
 * @property int $id
11
 * @property int $user_id
12
 *
13
 * @property \App\Models\User $user
14
 * @property \Illuminate\Database\Eloquent\Collection $claimed_jobs
15
 * @property \Jenssegers\Date\Date $created_at
16
 * @property \Jenssegers\Date\Date $updated_at
17
 *
18
 * Computed Properties
19
 * @property string $name
20
 * @property int[] $claimed_job_ids
21
 */
22
class HrAdvisor extends BaseModel
23
{
24
    use CrudTrait;
25
26
    /**
27
     * @var string[] $casts
28
     */
29
    protected $casts = [
30
        'user_id' => 'int'
31
    ];
32
33
    /**
34
     * The attributes that should be visible in arrays.
35
     *
36
     * @var array
37
     */
38
    protected $visible = ['id', 'user_id', 'name', 'claimed_job_ids'];
39
40
    /**
41
     * @var string[] $fillable
42
     */
43
    protected $fillable = [];
44
45
46
47
    /**
48
     * The accessors to append to the model's array form.
49
     *
50
     * @var array
51
     */
52
    protected $appends = ['name', 'claimed_job_ids'];
53
54
    public function user()
55
    {
56
        return $this->belongsTo(\App\Models\User::class);
57
    }
58
59
    public function claimed_jobs() //phpcs:ignore
60
    {
61
        return $this->belongsToMany(
62
            \App\Models\JobPoster::class,
63
            'claimed_jobs'
64
        );
65
    }
66
67
    /**
68
     * Return the full name of the User associated with this HR Advisor.
69
     *
70
     * @return string
71
     */
72
    public function getNameAttribute(): string
73
    {
74
        if ($this->user !== null) {
75
            return $this->user->first_name . ' ' . $this->user->last_name;
76
        }
77
        return '';
78
    }
79
80
    /**
81
     * Return an array of ids of claimed jobs.
82
     *
83
     * @return array
84
     */
85
    public function getClaimedJobIdsAttribute()
86
    {
87
        return $this->claimed_jobs()->allRelatedIds();
88
    }
89
}
90