CountriesController   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 39
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A index() 0 12 1
A show() 0 12 1
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