1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Xetaravel\Livewire\Discuss; |
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 Masmerise\Toaster\Toastable; |
14
|
|
|
use Xetaravel\Livewire\Forms\DiscussConversationForm; |
15
|
|
|
use Xetaravel\Models\DiscussConversation; |
16
|
|
|
|
17
|
|
|
class UpdateConversation extends Component |
18
|
|
|
{ |
19
|
|
|
use AuthorizesRequests; |
20
|
|
|
use Toastable; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* The form used to create/update a model. |
24
|
|
|
* |
25
|
|
|
* @var DiscussConversationForm |
26
|
|
|
*/ |
27
|
|
|
public DiscussConversationForm $form; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Used to show the Edit/Create modal. |
31
|
|
|
* |
32
|
|
|
* @var bool |
33
|
|
|
*/ |
34
|
|
|
public bool $showModal = false; |
35
|
|
|
|
36
|
|
|
public function mount(DiscussConversation $discussConversation): void |
37
|
|
|
{ |
38
|
|
|
$this->form->fill([ |
39
|
|
|
'discussConversation' => $discussConversation, |
40
|
|
|
'title' => $discussConversation->title, |
41
|
|
|
'category_id' => $discussConversation->category_id, |
42
|
|
|
'is_pinned' => $discussConversation->is_pinned, |
43
|
|
|
'is_locked' => $discussConversation->is_locked, |
44
|
|
|
]); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function render(): Factory|Application|View|\Illuminate\View\View |
48
|
|
|
{ |
49
|
|
|
return view('livewire.discuss.update-conversation'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* When a user click on 'Edit' open the modal. |
54
|
|
|
* |
55
|
|
|
* @return void |
56
|
|
|
*/ |
57
|
|
|
#[On('update-conversation')] |
58
|
|
|
public function updateConversation(): void |
59
|
|
|
{ |
60
|
|
|
$this->authorize('update', $this->form->discussConversation); |
61
|
|
|
|
62
|
|
|
$this->form->searchCategories(); |
63
|
|
|
|
64
|
|
|
$this->showModal = true; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Update the conversation. |
69
|
|
|
* |
70
|
|
|
* @return void |
71
|
|
|
*/ |
72
|
|
|
public function update(): void |
73
|
|
|
{ |
74
|
|
|
$this->authorize('update', $this->form->discussConversation); |
75
|
|
|
|
76
|
|
|
$this->validate(); |
77
|
|
|
|
78
|
|
|
$discussConversation = $this->form->update(); |
79
|
|
|
|
80
|
|
|
redirect() |
81
|
|
|
->route('discuss.conversation.show', ['slug' => $discussConversation->slug, 'id' => $discussConversation->getKey()]) |
|
|
|
|
82
|
|
|
->success('Your discussion has been updated successfully !'); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* We must use a function in the component. |
87
|
|
|
* |
88
|
|
|
* @param string $value |
89
|
|
|
* |
90
|
|
|
* @return void |
91
|
|
|
*/ |
92
|
|
|
public function searchCategories(string $value = ''): void |
93
|
|
|
{ |
94
|
|
|
$this->form->searchCategories($value); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
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.