UpdateArticle::render()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
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\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 Livewire\WithFileUploads;
14
use Masmerise\Toaster\Toastable;
15
use Xetaravel\Livewire\Forms\BlogArticleForm;
16
use Xetaravel\Models\BlogArticle;
17
use Throwable;
18
19
class UpdateArticle extends Component
20
{
21
    use AuthorizesRequests;
22
    use Toastable;
23
    use WithFileUploads;
0 ignored issues
show
introduced by
The trait Livewire\WithFileUploads requires some properties which are not provided by Xetaravel\Livewire\Admin\Blog\UpdateArticle: $map, $timestamp
Loading history...
24
25
    /**
26
     * The form used to create/update a model.
27
     *
28
     * @var BlogArticleForm
29
     */
30
    public BlogArticleForm $form;
31
32
    /**
33
     * Used to show the update modal.
34
     *
35
     * @var bool
36
     */
37
    public bool $showModal = false;
38
39
    public function render(): Factory|Application|View|\Illuminate\View\View
40
    {
41
        return view('livewire.admin.blog.update-article');
42
    }
43
44
    /**
45
     * When a user click on 'Edit' open the modal and set the content.
46
     *
47
     * @param BlogArticle $blogArticle
48
     *
49
     * @return void
50
     */
51
    #[On('update-article')]
52
    public function updateArticle(BlogArticle $blogArticle): void
53
    {
54
        $this->authorize('update', $blogArticle);
55
56
        $this->form->reset();
57
        $this->form->fill([
58
            'blogArticle' => $blogArticle,
59
            'title' => $blogArticle->title,
60
            'blog_category_id' => $blogArticle->blog_category_id,
61
            'content' => $blogArticle->content,
62
            'published_at' => $blogArticle->published_at?->format('Y-m-d H:i'),
63
        ]);
64
        $this->form->searchCategories();
65
66
        $this->showModal = true;
67
    }
68
69
    /**
70
     * Update the article.
71
     *
72
     * @return void
73
     *
74
     * @throws Throwable
75
     */
76
    public function update(): void
77
    {
78
        $this->authorize('update', $this->form->blogArticle);
79
80
        $this->validate();
81
82
        $this->form->update();
83
84
        redirect()
85
            ->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

85
            ->/** @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...
86
            ->success('Your article has been updated successfully !');
87
    }
88
}
89