Completed
Push — master ( d44ef5...c7e879 )
by Fèvre
12s
created

CategoryController::index()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
dl 8
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
namespace Xetaravel\Http\Controllers\Discuss;
3
4
use Illuminate\View\View;
5
use Xetaravel\Models\DiscussCategory;
6
use Xetaravel\Models\DiscussConversation;
7
8
class CategoryController extends Controller
9
{
10
    /**
11
     * View all categories.
12
     *
13
     * @return \Illuminate\View\View
14
     */
15 View Code Duplication
    public function index(): View
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
16
    {
17
        $categories = DiscussCategory::orderBy('title', 'asc')->get();
18
19
        $breadcrumbs = $this->breadcrumbs->addCrumb('All Categories', route('discuss.category.index'));
20
21
        return view('Discuss::category.index', compact('categories', 'breadcrumbs'));
22
    }
23
24
    /**
25
     * Display all conversations related to the category.
26
     *
27
     * @return \Illuminate\View\View
28
     */
29
    public function show(string $slug, int $id): View
0 ignored issues
show
Unused Code introduced by
The parameter $slug is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
30
    {
31
        $category = DiscussCategory::findOrFail($id);
32
33
        $conversations = DiscussConversation::where('category_id', $category->getKey())
34
            ->with('User', 'Category', 'FirstPost', 'LastPost')
35
            ->orderBy('is_pinned', 'desc')
36
            ->orderBy('created_at', 'desc')
37
            ->paginate(config('xetaravel.pagination.discuss.conversation_per_page'));
38
39
        $this->breadcrumbs->addCrumb('Categories', route('discuss.category.index'));
40
41
        $breadcrumbs = $this->breadcrumbs->addCrumb(
42
            e($category->title),
43
            route('discuss.category.show', ['slug' => $category->slug,'id' => $category->getKey()])
44
        );
45
46
        return view('Discuss::category.show', compact('breadcrumbs', 'conversations', 'category'));
47
    }
48
}
49