Passed
Push — dependabot/npm_and_yarn/string... ( b56eb5...bc569b )
by
unknown
45:46 queued 33s
created

InternalLinksController   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 17
ccs 0
cts 7
cp 0
rs 10
c 0
b 0
f 0
wmc 2
1
<?php
2
3
namespace Thinktomorrow\Chief\App\Http\Controllers\Api;
4
5
use Illuminate\Http\Request;
6
use Thinktomorrow\Chief\App\Http\Controllers\Controller;
7
use Thinktomorrow\Chief\FlatReferences\FlatReferencePresenter;
8
use Thinktomorrow\Chief\Pages\Page;
9
10
class InternalLinksController extends Controller
11
{
12
    public function index(Request $request)
13
    {
14
        // Fetch the links for specific locale
15
        if ($request->has('locale')) {
16
            app()->setLocale($request->get('locale'));
17
        }
18
19
        $links = Page::all()->map(function ($page) {
20
            return [
21
                'name' => $page->menuLabel(),
22
                'url' => $page->url(),
23
            ];
24
        });
25
26
        return response()->json($links->prepend(['name' => '...', 'url' => ''])->all());
27
    }
28
}
29