UpdateCategory::update()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 11
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Xetaravel\Livewire\Admin\Discuss;
6
7
use Illuminate\Contracts\View\Factory;
8
use Illuminate\Contracts\View\View;
9
use Illuminate\Foundation\Application;
10
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
11
use Livewire\Attributes\On;
12
use Livewire\Component;
13
use Masmerise\Toaster\Toastable;
14
use Xetaravel\Livewire\Forms\DiscussCategoryForm;
15
use Xetaravel\Models\DiscussCategory;
16
17
class UpdateCategory extends Component
18
{
19
    use AuthorizesRequests;
20
    use Toastable;
21
22
    /**
23
     * The form used to create/update a model.
24
     *
25
     * @var DiscussCategoryForm
26
     */
27
    public DiscussCategoryForm $form;
28
29
    /**
30
     * Used to show the update modal.
31
     *
32
     * @var bool
33
     */
34
    public bool $showModal = false;
35
36
    public function render(): View|Application|Factory|\Illuminate\View\View
37
    {
38
        return view('livewire.admin.discuss.update-category');
39
    }
40
41
    /**
42
     * When a user click on 'Edit' open the modal and set the content.
43
     *
44
     * @param DiscussCategory $discussCategory
45
     *
46
     * @return void
47
     */
48
    #[On('update-category')]
49
    public function updateCategory(DiscussCategory $discussCategory): void
50
    {
51
        $this->authorize('update', $discussCategory);
52
53
        $this->form->reset();
54
        $this->form->fill([
55
            'discussCategory' => $discussCategory,
56
            'title' => $discussCategory->title,
57
            'color' => $discussCategory->color,
58
            'icon' => $discussCategory->icon,
59
            'level' => $discussCategory->level,
60
            'is_locked' => $discussCategory->is_locked,
61
            'description' => $discussCategory->description,
62
        ]);
63
64
        $this->showModal = true;
65
    }
66
67
    /**
68
     * Update the category.
69
     *
70
     * @return void
71
     */
72
    public function update(): void
73
    {
74
        $this->authorize('update', $this->form->discussCategory);
75
76
        $this->validate();
77
78
        $this->form->update();
79
80
        redirect()
81
            ->route('admin.discuss.category.index')
0 ignored issues
show
Bug introduced by
The method route() does not exist on Illuminate\Routing\Redirector. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

81
            ->/** @scrutinizer ignore-call */ route('admin.discuss.category.index')

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
82
            ->success('Your category has been updated successfully !');
83
    }
84
}
85