Files
UNIT3D-Community-Edition/app/Http/Livewire/Comments.php
T
2022-06-15 19:08:37 -04:00

90 lines
2.4 KiB
PHP

<?php
/**
* NOTICE OF LICENSE.
*
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D Community Edition
*
* @author HDVinnie <hdinnovations@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/
namespace App\Http\Livewire;
use App\Achievements\UserMade100Comments;
use App\Achievements\UserMade200Comments;
use App\Achievements\UserMade300Comments;
use App\Achievements\UserMade400Comments;
use App\Achievements\UserMade500Comments;
use App\Achievements\UserMade50Comments;
use App\Achievements\UserMade600Comments;
use App\Achievements\UserMade700Comments;
use App\Achievements\UserMade800Comments;
use App\Achievements\UserMade900Comments;
use App\Achievements\UserMadeComment;
use App\Achievements\UserMadeTenComments;
use Livewire\Component;
use Livewire\WithPagination;
use voku\helper\AntiXSS;
class Comments extends Component
{
use WithPagination;
public $model;
public $anon = 0;
protected $listeners = [
'refresh' => '$refresh',
];
public $newCommentState = [
'content' => '',
];
protected $validationAttributes = [
'newCommentState.content' => 'comment',
];
final public function postComment(): void
{
if (\auth()->user()->can_comment === 0) {
$this->dispatchBrowserEvent('error', ['type' => 'error', 'message' => \trans('comment.rights-revoked')]);
return;
}
$this->validate([
'newCommentState.content' => 'required',
]);
$comment = $this->model->comments()->make((new AntiXSS())->xss_clean($this->newCommentState));
$comment->user()->associate(\auth()->user());
$comment->anon = $this->anon;
$comment->save();
$this->newCommentState = [
'content' => '',
];
$this->goToPage(1);
}
final public function render(): \Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|\Illuminate\Contracts\Foundation\Application
{
$comments = $this->model
->comments()
->with('user', 'children.user', 'children.children')
->parent()
->latest()
->paginate(10);
return \view('livewire.comments', [
'comments' => $comments,
]);
}
}