Passed
Push — 5.0.0 ( 49e1c0...87aae2 )
by Fèvre
06:22
created

CreateArticle::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 13
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Xetaravel\Livewire\Admin\Blog;
6
7
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
8
use Livewire\Attributes\On;
9
use Livewire\Component;
10
use Livewire\WithFileUploads;
11
use Masmerise\Toaster\Toastable;
12
use Throwable;
13
use Xetaravel\Livewire\Forms\BlogArticleForm;
14
use Xetaravel\Models\BlogArticle;
15
16
class CreateArticle extends Component
17
{
18
    use AuthorizesRequests;
19
    use Toastable;
20
    use WithFileUploads;
0 ignored issues
show
introduced by
The trait Livewire\WithFileUploads requires some properties which are not provided by Xetaravel\Livewire\Admin\Blog\CreateArticle: $map, $timestamp
Loading history...
21
22
    /**
23
     * The form used to create/update a model.
24
     *
25
     * @var BlogArticleForm
26
     */
27
    public BlogArticleForm $form;
28
29
    /**
30
     * Used to show the create modal.
31
     *
32
     * @var bool
33
     */
34
    public bool $showModal = false;
35
36
    /**
37
     * Create a blank model and assign it to the model. (Used in create modal)
38
     *
39
     * @return void
40
     */
41
    #[On('create-article')]
42
    public function createArticle(): void
43
    {
44
        $this->authorize('create', BlogArticle::class);
45
46
        $this->form->reset();
47
        $this->form->searchCategories();
48
49
        $this->showModal = true;
50
    }
51
52
    /**
53
     * Validate and save the model.
54
     *
55
     * @return void
56
     *
57
     * @throws Throwable
58
     */
59
    public function create(): void
60
    {
61
        $this->authorize('create', BlogArticle::class);
62
63
        $this->validate();
64
65
        $this->form->create();
66
67
        $this->showModal = false;
68
69
        redirect()
70
            ->route('admin.blog.article.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

70
            ->/** @scrutinizer ignore-call */ route('admin.blog.article.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...
71
            ->success('Your article has been created successfully !');
72
    }
73
74
    public function render()
75
    {
76
        return view('livewire.admin.blog.create-article');
77
    }
78
79
    /**
80
     * We must use a function in the component.
81
     *
82
     * @param string $value
83
     *
84
     * @return void
85
     */
86
    public function searchCategories(string $value = ''): void
87
    {
88
        $this->form->searchCategories($value);
89
    }
90
}
91