CountriesController::show()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 12
rs 10
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use Illuminate\Http\Request;
6
use App\Country;
7
8
class CountriesController extends Controller
9
{
10
    /**
11
     * Lists all countries with the total of spots available for each one
12
     *
13
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
14
     */
15
    public function index()
16
    {
17
        $countries = Country::whereHas('spots', function ($query) {
18
            $query->where('is_approved', true);
19
        })
20
        ->withCount(['spots' => function ($query) {
21
            $query->where('is_approved', true);
22
        }])
23
        ->orderBy('name_pt', 'ASC')
24
        ->get();
25
26
        return view('countries.index', compact('countries'));
27
    }
28
29
    /**
30
     * Show a list of all the spots for a specific country
31
     *
32
     * @param $countrySlug
33
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
34
     */
35
    public function show(String $countrySlug)
36
    {
37
        $country = Country::where('slug_pt', $countrySlug)
38
            ->with(['spots' => function ($query) {
39
                $query->orderBy('city', 'ASC');
40
            }])
41
            ->whereHas('spots', function ($query) {
42
                $query->where('is_approved', true);
43
            })
44
            ->firstOrFail();
45
46
        return view('countries.show', compact('country'));
47
    }
48
}
49