1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Xetaravel\Livewire\Discuss; |
6
|
|
|
|
7
|
|
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests; |
8
|
|
|
use Illuminate\Http\RedirectResponse; |
9
|
|
|
use Illuminate\Support\Facades\DB; |
10
|
|
|
use Livewire\Attributes\On; |
11
|
|
|
use Livewire\Component; |
12
|
|
|
use Livewire\Features\SupportRedirects\Redirector; |
13
|
|
|
use Masmerise\Toaster\Toastable; |
14
|
|
|
use Xetaravel\Models\DiscussConversation; |
15
|
|
|
use Throwable; |
16
|
|
|
|
17
|
|
|
class DeleteConversation extends Component |
18
|
|
|
{ |
19
|
|
|
use AuthorizesRequests; |
20
|
|
|
use Toastable; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* The form used to create/update a model. |
24
|
|
|
* |
25
|
|
|
* @var DiscussConversation |
26
|
|
|
*/ |
27
|
|
|
public DiscussConversation $discussConversation; |
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->discussConversation = $discussConversation; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function render() |
42
|
|
|
{ |
43
|
|
|
return view('livewire.discuss.delete-conversation'); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Show the confirmation modal to delete a conversation. |
48
|
|
|
* |
49
|
|
|
* @return void |
50
|
|
|
*/ |
51
|
|
|
#[On('delete-conversation')] |
52
|
|
|
public function deleteConversation(): void |
53
|
|
|
{ |
54
|
|
|
$this->authorize('delete', $this->discussConversation); |
55
|
|
|
|
56
|
|
|
$this->showModal = true; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Delete a conversation. |
61
|
|
|
* |
62
|
|
|
* @return RedirectResponse|Redirector|null |
63
|
|
|
* |
64
|
|
|
* @throws Throwable |
65
|
|
|
*/ |
66
|
|
|
public function delete(): Redirector|RedirectResponse|null |
67
|
|
|
{ |
68
|
|
|
$this->authorize('delete', $this->discussConversation); |
69
|
|
|
|
70
|
|
|
// We need to re-fetch the conversation for loading relations to prevent lazy loads. |
71
|
|
|
$this->discussConversation = DiscussConversation::with('category', 'posts', 'posts.conversation', 'discussLogs') |
72
|
|
|
->findOrFail($this->discussConversation->id); |
73
|
|
|
|
74
|
|
|
$result = DB::transaction(function () { |
75
|
|
|
return $this->discussConversation->delete(); |
76
|
|
|
}); |
77
|
|
|
|
78
|
|
|
if ($result) { |
79
|
|
|
return redirect() |
80
|
|
|
->route('discuss.index') |
|
|
|
|
81
|
|
|
->success('This discussion has been deleted successfully !'); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
$this->showModal = false; |
85
|
|
|
|
86
|
|
|
return back() |
87
|
|
|
->error('An error occurred while deleting this discussion !'); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
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.