GlobalSearchController::index()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 14
ccs 0
cts 10
cp 0
crap 2
rs 9.9666
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