Hello everyone, i have this problem:
Livewire encountered corrupt data when trying to hydrate the [news-comments] component. Ensure that the [name, id, data] of the Livewire component wasn’t tampered with between requests.
Code Controller:
class NewsComments extends Component
{
public $text;
protected $comments;
public function render(){
$this->comments = \App\Comments_news::
join('users', 'comments_news.user_id', '=', 'users.id')
->join('news', 'comments_news.news_id', '=', 'news.id')
->select('comments_news.txt','comments_news.created_at','users.name','users.img','users.id')
->where('comments_news.news_id','=',$this->id)
->orderByDesc('comments_news.id')
->paginate(5);
return view('livewire.news-comments',['comments' => $this->comments]);
}
public function mount($news){
$this->id = $news->id;
}
public function addComment(){
\App\Comments_news::create([
'txt' => $this->text,
'user_id' => Auth::id(),
'news_id' => $this->id,
]);
}
}
Input “text” and button “addComment”:
<div class="row d-flex justify-content-center">
<div class="col-md-8 col-lg-8 col-12">
<textarea id="addComment" name="addComment" style="width: 100%; min-height:80px;" wire:model="news_text"></textarea>
</div>
</div>
<div class="row">
<div class="col d-flex d-sm-flex d-xl-flex justify-content-end" style="margin: 0 0 15px 0;">
<button class="btn btn-dark text-white d-xl-flex" wire:click="addComment()" type="submit">Add Comment</button>
</div>
</div>
And this parameter in livewire directive:
@livewire(‘news-comments’, [‘news’=>$news])