Passed
Push — task/ide-helper ( 0e23d8...f2b248 )
by Grant
12:57 queued 05:25
created

Department::department_translations()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * Created by Reliese Model.
5
 * Date: Thu, 12 Jul 2018 22:39:27 +0000.
6
 */
7
8
namespace App\Models\Lookup;
9
10
use App\Models\BaseModel;
11
12
use Backpack\CRUD\app\Models\Traits\CrudTrait;
13
use Backpack\CRUD\app\Models\Traits\SpatieTranslatable\HasTranslations;
14
15
/**
16
 * Class Department
17
 * @property int $id
18
 * @property string $name
19
 * @property string $impact
20
 * @property string $preference
21
 *
22
 * @property \Jenssegers\Date\Date $created_at
23
 * @property \Jenssegers\Date\Date $updated_at
24
 *
25
 * @property \Illuminate\Database\Eloquent\Collection $managers
26
 * @property \Illuminate\Database\Eloquent\Collection $job_posters
27
 *
28
 * Localized Properties:
29
 * @property string $name
30
 * @property string $impact
31
 * @property string $preference
32
 *
33
 * Methods
34
 * @method mixed[] toApiArray()
35
 */
36
class Department extends BaseModel
37
{
38
    use CrudTrait;
0 ignored issues
show
introduced by
The trait Backpack\CRUD\app\Models\Traits\CrudTrait requires some properties which are not provided by App\Models\Lookup\Department: $Type, $fakeColumns
Loading history...
39
    use HasTranslations;
40
41
    /**
42
     * @var $translatable string[]
0 ignored issues
show
Documentation Bug introduced by
The doc comment $translatable at position 0 could not be parsed: Unknown type name '$translatable' at position 0 in $translatable.
Loading history...
43
     * */
44
    public $translatable = [
45
        'name',
46
        'impact',
47
        'preference',
48
    ];
49
50
    /**
51
     * @var $fillable string[]
0 ignored issues
show
Documentation Bug introduced by
The doc comment $fillable at position 0 could not be parsed: Unknown type name '$fillable' at position 0 in $fillable.
Loading history...
52
     * */
53
    protected $fillable = [
54
        'name',
55
        'impact',
56
        'preference',
57
    ];
58
59
    public function managers() // phpcs:ignore
60
    {
61
        return $this->hasMany(\App\Models\Manager::class);
62
    }
63
64
    public function department_translations() // phpcs:ignore
65
    {
66
        return $this->hasMany(\App\Models\Lookup\DepartmentTranslation::class);
67
    }
68
69
    public function job_posters() // phpcs:ignore
70
    {
71
        return $this->hasMany(\App\Models\JobPoster::class);
72
    }
73
74
    /**
75
     * Return the array of values used to represent this object in an api response.
76
     *
77
     * @return mixed[]
78
     */
79
    public function toApiArray()
0 ignored issues
show
introduced by
Method \App\Models\Lookup\Department::toApiArray() does not have return type hint for its return value but it should be possible to add it based on @return annotation "mixed[]".
Loading history...
80
    {
81
        $deptArray = ['id' => $this->id];
82
        foreach (['en', 'fr'] as $locale) {
83
            $deptArray[$locale] = [
84
                'name' => $this->getTranslation('name', $locale),
85
                'impact' => $this->getTranslation('impact', $locale),
86
            ];
87
        }
88
        return $deptArray;
89
    }
90
}
91