XetaIO /
Xetaravel
| 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 Illuminate\Support\Facades\Auth; |
||||
| 12 | use Livewire\Attributes\On; |
||||
| 13 | use Livewire\Component; |
||||
| 14 | use Masmerise\Toaster\Toastable; |
||||
| 15 | use Xetaravel\Livewire\Forms\DiscussConversationForm; |
||||
| 16 | use Xetaravel\Models\DiscussConversation; |
||||
| 17 | use Throwable; |
||||
| 18 | |||||
| 19 | class CreateConversation extends Component |
||||
| 20 | { |
||||
| 21 | use AuthorizesRequests; |
||||
| 22 | use Toastable; |
||||
| 23 | |||||
| 24 | /** |
||||
| 25 | * The form used to create/update a model. |
||||
| 26 | * |
||||
| 27 | * @var DiscussConversationForm |
||||
| 28 | */ |
||||
| 29 | public DiscussConversationForm $form; |
||||
| 30 | |||||
| 31 | /** |
||||
| 32 | * Used to show the Edit/Create modal. |
||||
| 33 | * |
||||
| 34 | * @var bool |
||||
| 35 | */ |
||||
| 36 | public bool $showModal = false; |
||||
| 37 | |||||
| 38 | public function render(): Factory|Application|View|\Illuminate\View\View |
||||
| 39 | { |
||||
| 40 | return view('livewire.discuss.create-conversation'); |
||||
| 41 | } |
||||
| 42 | |||||
| 43 | /** |
||||
| 44 | * Create a blank model and assign it to the model. (Used in create modal) |
||||
| 45 | * |
||||
| 46 | * @return void |
||||
| 47 | */ |
||||
| 48 | #[On('create-conversation')] |
||||
| 49 | public function createConversation(): void |
||||
| 50 | { |
||||
| 51 | $this->authorize('create', DiscussConversation::class); |
||||
| 52 | |||||
| 53 | $this->form->reset(); |
||||
| 54 | $this->form->searchCategories(); |
||||
| 55 | |||||
| 56 | $this->showModal = true; |
||||
| 57 | } |
||||
| 58 | |||||
| 59 | /** |
||||
| 60 | * Validate and save the model. |
||||
| 61 | * |
||||
| 62 | * @return void |
||||
| 63 | * |
||||
| 64 | * @throws Throwable |
||||
| 65 | */ |
||||
| 66 | public function create(): void |
||||
| 67 | { |
||||
| 68 | $this->authorize('create', DiscussConversation::class); |
||||
| 69 | |||||
| 70 | $this->validate(); |
||||
| 71 | |||||
| 72 | if (DiscussConversation::isFlooding('xetaravel.flood.discuss.conversation') && |
||||
| 73 | !Auth::user()->hasPermissionTo('manage discuss conversation')) { |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 74 | $this->error('Wow, keep calm bro, and try to not flood !'); |
||||
| 75 | |||||
| 76 | return; |
||||
| 77 | } |
||||
| 78 | $discussConversation = $this->form->create(); |
||||
| 79 | |||||
| 80 | redirect() |
||||
| 81 | ->route('discuss.conversation.show', ['slug' => $discussConversation->slug, 'id' => $discussConversation->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
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...
|
|||||
| 82 | ->success('Your discussion has been created 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 |