51 lines
1.3 KiB
PHP
51 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Tools;
|
|
|
|
use App\Models\Comment;
|
|
use Livewire\Attributes\Rule;
|
|
use Livewire\Component;
|
|
|
|
class HomeComments extends Component
|
|
{
|
|
|
|
|
|
public Comment $comments;
|
|
public Comment $comment;
|
|
|
|
#[Rule('required')]
|
|
public $comment_name;
|
|
#[Rule('required')]
|
|
public $comment_message;
|
|
public $comment_name_reply;
|
|
public $comment_message_reply;
|
|
|
|
public $blog_id;
|
|
public $comment_id;
|
|
|
|
public function mount($comments,$comment,$blog_id)
|
|
{
|
|
$this->comments = $comments;
|
|
$this->comment = $comment;
|
|
$this->blog_id = $blog_id;
|
|
// dd($this->comment);
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.tools.home-comments');
|
|
}
|
|
|
|
public function reply($id,$parent_id)
|
|
{
|
|
if ($this->comment_message_reply && $this->comment_name_reply){
|
|
|
|
Comment::create(['name'=>$this->comment_name_reply,'message'=>$this->comment_message_reply,'blog_id'=>$this->blog_id,'ip'=>request()->ip(),'user_agent'=>request()->userAgent(),'parent_id'=>$id,'type'=>2]);
|
|
Comment::where('id',$parent_id)->increment('reply');
|
|
$this->comment_message_reply=null;
|
|
$this->comment_name_reply=null;
|
|
}
|
|
}
|
|
|
|
}
|