Passed
Push — discuss-search ( 2abe54 )
by Fèvre
08:12
created

SearchController   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 25
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A index() 0 17 1
1
<?php
2
namespace Xetaravel\Http\Controllers\Discuss;
3
4
use Illuminate\Http\Request;
5
use Illuminate\Http\RedirectResponse;
6
use Illuminate\View\View;
7
use Xetaravel\Models\DiscussConversation;
8
9
class SearchController extends Controller
10
{
11
12
    /**
13
     * Show the search update form.
14
     *
15
     * @return \Illuminate\View\View
16
     */
17
    public function index(Request $request): View
18
    {
19
        $search = $request->get('search');
20
21
        $conversations = DiscussConversation::where('title', 'like', '%' . $search . '%')
22
            ->orWhereHas('posts', function ($query) use ($search) {
23
                return $query->where('content', 'like', '%' . $search . '%');
24
            })
25
            ->orderBy('is_pinned', 'desc')
26
            ->orderBy('created_at', 'desc')
27
            ->paginate(config('xetaravel.pagination.discuss.conversation_per_page'));
28
29
        $this->breadcrumbs->addCrumb('Search : ' . $search, route('users.account.index'));
30
31
        $breadcrumbs = $this->breadcrumbs;
32
33
        return view('Discuss::search.index', compact('breadcrumbs', 'conversations', 'search'));
34
    }
35
}
36