【发布时间】:2018-10-09 05:26:29
【问题描述】:
我目前正在关注有关 laravel 的 websocket 的教程。 我完全喜欢这个教程,但是.... 这是代码 控制器:
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;
}}
路由/api 文件
Route::get('/post/{post}', 'CommentController@getcomments');
Route::middleware('auth:api')->group(function () {
Route::post('/post/{post}', 'CommentController@addcomment');});
在教程中,当他转到 /post/1 时,它会在 post.blade.php 中显示 html 代码
这就是我从中得到的 enter image description here
请帮忙:)
【问题讨论】:
标签: javascript json laravel websocket response