hi i have a livewire component for storing the comment for user and showing the result immediately without refreshing the page but what happens is that when i add a comment this comment is not appear unless i refreshed the page manually while it is suppose to apper immidiatly and here is the code
<?php
namespace App\Http\Livewire;
use App\Models\Comment;
use Livewire\Component;
class Comments extends Component
{
public $comments;
public $comment;
public $user_id = 1;
public function mount($comments): void
{
$this->comments = $comments;
}
public function store()
{
$created_comment = Comment::create([
'body' => $this->comment,
'user_id' => $this->user_id
]);
return $created_comment->save();
}
public function render()
{
return view('livewire.comments');
}
}
<?php
namespace App\Http\Controllers;
use App\Models\Comment;
use Illuminate\Http\Request;
class CommentsController extends Controller
{
public function index(){
return view('comments',[
'title'=>'index',
'comments'=> Comment::with('author')->get()]);
}
}