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

CreateCategory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 57
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 3 1
A createCategory() 0 8 1
A create() 0 13 1
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 CreateCategory 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 create modal.
29
     *
30
     * @var bool
31
     */
32
    public bool $showModal = false;
33
34
    /**
35
     * Create a blank model and assign it to the model. (Used in create modal)
36
     *
37
     * @return void
38
     */
39
    #[On('create-category')]
40
    public function createCategory(): void
41
    {
42
        $this->authorize('create', DiscussCategory::class);
43
44
        $this->form->reset();
45
46
        $this->showModal = true;
47
    }
48
49
    /**
50
     * Validate and save the model.
51
     *
52
     * @return void
53
     */
54
    public function create(): void
55
    {
56
        $this->authorize('create', DiscussCategory::class);
57
58
        $this->validate();
59
60
        $this->form->create();
61
62
        $this->showModal = false;
63
64
        redirect()
65
            ->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

65
            ->/** @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...
66
            ->success('Your category has been created successfully !');
67
    }
68
69
    public function render(): View|Application|Factory|\Illuminate\View\View
70
    {
71
        return view('livewire.admin.discuss.create-category');
72
    }
73
}
74