I've been learning about Laravel's websocket and following a tutorial on it. I tried to implement the code exactly as shown in the tutorial, but I'm running into some issues. Here is the code for the controller:
class CommentController extends Controller{
public function getcomments(Post $post){
return response()->json($post->comments()->with('user')->latest()->get());
}
public function addcomment(Request $req, Post $post){
$comment = $post->comment()->create([
'body' => $req->body,
'user_id' => auth::id()
]);
$comment = Comment::where('id', $comment->id)->with('user')->first();
return $comment->toJson;
}}
And here are the routes defined in the routes/api file:
Route::get('/post/{post}', 'CommentController@getcomments');
Route::middleware('auth:api')->group(function () {
Route::post('/post/{post}', 'CommentController@addcomment');});
In the tutorial, when the instructor goes to /post/1, it displays the HTML code in the post.blade.php template.
However, when I try the same, this is what I see: enter image description here
Could anyone provide some assistance with this issue? Thanks! :)