Total Complexity | 6 |
Total Lines | 82 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
9 | class RegionRepository |
||
10 | { |
||
11 | /** |
||
12 | * Get all Regions. |
||
13 | * |
||
14 | * @return \Illuminate\Support\Collection |
||
15 | */ |
||
16 | public function getAll(): Collection |
||
17 | { |
||
18 | return Region::orderBy('name')->get(); |
||
19 | } |
||
20 | |||
21 | /** |
||
22 | * Get Region by id |
||
23 | * |
||
24 | * @param int $id |
||
25 | * @return Region |
||
26 | */ |
||
27 | public function getById(int $id) |
||
28 | { |
||
29 | return Region::findOrFail($id); |
||
30 | } |
||
31 | |||
32 | /** |
||
33 | * Store Region |
||
34 | * |
||
35 | * @param array $data |
||
36 | * @return Region |
||
37 | */ |
||
38 | public function store(array $data): Region |
||
39 | { |
||
40 | $region = new Region(); |
||
41 | $region = self::assignDataAttributes($region, $data); |
||
|
|||
42 | |||
43 | $region->save(); |
||
44 | |||
45 | return $region->fresh(); |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * Update Region |
||
50 | * |
||
51 | * @param array $data |
||
52 | * @param int $id |
||
53 | * @return Region |
||
54 | */ |
||
55 | public function update(array $data, int $id): Region |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * Delete Region |
||
67 | * |
||
68 | * @param int $id |
||
69 | * @return void |
||
70 | */ |
||
71 | public function delete(int $id): void |
||
74 | } |
||
75 | |||
76 | /** |
||
77 | * Assign the attributes of the data array to the object |
||
78 | * |
||
79 | * @param \App\Models\Region $region |
||
80 | * @param array $data |
||
81 | * |
||
82 | * @return \App\Models\Region |
||
83 | */ |
||
84 | public function assignDataAttributes(Region $region, array $data): Region |
||
93 |