Issues (264)

app/Livewire/Discuss/UpdatePost.php (1 issue)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Xetaravel\Livewire\Discuss;
6
7
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
8
use Livewire\Attributes\On;
9
use Livewire\Component;
10
use Masmerise\Toaster\Toastable;
11
use Xetaravel\Livewire\Forms\DiscussPostForm;
12
use Xetaravel\Models\DiscussPost;
13
14
class UpdatePost extends Component
15
{
16
    use AuthorizesRequests;
17
    use Toastable;
18
19
    /**
20
     * The form used to create/update a model.
21
     *
22
     * @var DiscussPostForm
23
     */
24
    public DiscussPostForm $form;
25
26
    /**
27
     * Used to show the Edit/Create modal.
28
     *
29
     * @var bool
30
     */
31
    public bool $showModal = false;
32
33
    public function render()
34
    {
35
        return view('livewire.discuss.update-post');
36
    }
37
38
    /**
39
     * When a user click on 'Edit' open the modal and set the content.
40
     *
41
     * @param DiscussPost $discussPost
42
     *
43
     * @return void
44
     */
45
    #[On('update-post')]
46
    public function updatePost(DiscussPost $discussPost): void
47
    {
48
        $this->authorize('update', $discussPost);
49
50
        $this->form->reset();
51
        $this->form->discussPost = $discussPost;
52
        $this->form->content = $discussPost->content;
53
54
        $this->showModal = true;
55
    }
56
57
    /**
58
     * Update the post.
59
     *
60
     * @return void
61
     */
62
    public function update(): void
63
    {
64
        $this->authorize('update', $this->form->discussPost);
65
66
        $this->validate();
67
68
        $discussPost = $this->form->update();
69
70
        redirect()
71
            ->route('discuss.post.show', ['id' => $discussPost->getKey()])
0 ignored issues
show
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

71
            ->/** @scrutinizer ignore-call */ route('discuss.post.show', ['id' => $discussPost->getKey()])

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...
72
            ->success('Your reply has been edited successfully !');
73
    }
74
}
75