Passed
Push — 5.0.0 ( 233e11...ab4a40 )
by Fèvre
05:22
created

UpdateCategory::updateCategory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

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

77
            ->/** @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...
78
            ->success('Your category has been updated successfully !');
79
    }
80
}
81