Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
NewsController
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 index
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace Engelsystem\Controllers\Api;
6
7use Engelsystem\Controllers\Api\Resources\NewsResource;
8use Engelsystem\Http\Response;
9use Engelsystem\Models\News;
10
11class NewsController extends ApiController
12{
13    public function index(): Response
14    {
15        $models = News::query()
16            ->orderByDesc('updated_at')
17            ->orderByDesc('created_at')
18            ->get();
19
20        $data = ['data' => NewsResource::collection($models)];
21        return $this->response
22            ->withContent(json_encode($data));
23    }
24}