Completed
Push — master ( c99589...beb3f5 )
by Scott
02:24
created

Categories::show()   A

Complexity

Conditions 2
Paths 3

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 12
nc 3
nop 2
1
<?php namespace Bedard\Shop\Api;
2
3
use Bedard\Shop\Classes\ApiController;
4
use Bedard\Shop\Models\ApiSettings;
5
use Bedard\Shop\Repositories\CategoryRepository;
6
use Exception;
7
use Log;
8
9
class Categories extends ApiController
10
{
11
    /**
12
     * List all categories.
13
     *
14
     * @return \October\Rain\Database\Collection
15
     */
16
    public function index(CategoryRepository $repository)
17
    {
18
        try {
19
            $params = [
20
                'hide_empty' => ApiSettings::categoriesHideEmpty(),
21
                'load_thumbnails' => ApiSettings::categoriesLoadThumbnails(),
22
                'select' => ApiSettings::categoriesSelect(),
23
            ];
24
25
            return $repository->get($params);
26
        } catch (Exception $e) {
27
            Log::error($e->getMessage());
28
29
            abort(500, $e->getMessage());
30
        }
31
    }
32
33
    /**
34
     * Find a single category.
35
     *
36
     * @param  \Bedard\Shop\Repositories\CategoryRepository $repository
37
     * @param  string                                       $slug
38
     * @return \Bedard\Shop\Models\Category
39
     */
40
    public function show(CategoryRepository $repository, $slug)
41
    {
42
        try {
43
            $params = [
44
                'load_products' => ApiSettings::categoryLoadProducts(),
45
                'load_products_thumbnails' => ApiSettings::categoryLoadProductsThumbnails(),
46
                'load_thumbnails' => ApiSettings::categoryLoadThumbnails(),
47
                'products_select' => ApiSettings::categoryProductsSelect(),
48
                'select' => ApiSettings::categorySelect(),
49
            ];
50
51
            return $repository->show($slug, $params);
52
        } catch (Exception $e) {
53
            Log::error($e->getMessage());
54
55
            abort(500, $e->getMessage());
56
        }
57
    }
58
}
59