Total Complexity | 2 |
Total Lines | 26 |
Duplicated Lines | 0 % |
Coverage | 0% |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
7 | class DepartmentController extends Controller |
||
8 | { |
||
9 | /** |
||
10 | * Return all departments as an array |
||
11 | * |
||
12 | * @return mixed |
||
13 | */ |
||
14 | public function index() |
||
15 | { |
||
16 | $departments = Department::all(); |
||
17 | $departmentsArray = []; |
||
18 | // TODO: improve effiency of getting translations. |
||
19 | foreach ($departments as $department) { |
||
20 | $translations = [ |
||
21 | 'en' => [ |
||
22 | 'name' => $department->getTranslation('name', 'en'), |
||
23 | 'impact' => $department->getTranslation('impact', 'en'), |
||
24 | ], |
||
25 | 'fr' => [ |
||
26 | 'name' => $department->getTranslation('name', 'fr'), |
||
27 | 'impact' => $department->getTranslation('impact', 'fr'), |
||
28 | ] |
||
29 | ]; |
||
30 | $departmentsArray[] = array_merge($department->toArray(), $translations); |
||
31 | } |
||
32 | return ['departments' => $departmentsArray]; |
||
33 | } |
||
35 |