GlobalSearchController   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 24
ccs 0
cts 10
cp 0
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A index() 0 14 1
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Http\Requests\GlobalSearchRequest;
6
use App\Models\Glossary;
7
use App\Models\Insight;
8
use App\Models\Post;
9
use App\Models\Quote;
10
use Illuminate\View\View;
11
use Spatie\Searchable\Search;
12
13
class GlobalSearchController extends Controller
14
{
15
16
    /**
17
     * Display a listing of the resource.
18
     *
19
     * @param \App\Http\Requests\GlobalSearchRequest $request
20
     *
21
     * @return \Illuminate\View\View
22
     */
23
    public function index(GlobalSearchRequest $request): View
24
    {
25
        $query = $request->keyword;
26
27
        $searchResults = (new Search())
28
            ->registerModel(Post::class, ['title'])
29
            ->registerModel(Glossary::class, ['term', 'definition'])
30
            ->registerModel(Quote::class, ['author', 'description'])
31
            ->registerModel(Insight::class, ['title', 'body'])
32
33
            ->search($query);
34
35
        return view('globalSearch.index', [
36
            'searchResults' => $searchResults,
37
        ]);
38
    }
39
}
40