【问题标题】:why is laravel not displaying the blade?为什么 laravel 不显示刀片?
【发布时间】: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


    【解决方案1】:

    可能您的教程视频要求您访问/post/1,但/api/post/1 是您所做的。该 API 可能用于获取位于 /post/1id:1 的所有帖子的 cmets。

    【讨论】:

    • 1/方法名称必须是 index() 而不是 getcmets()(我想知道它对他是如何工作的)。 2/正如你所说,它的/post/id。它现在可以工作了,谢谢
    猜你喜欢
    • 2022-01-10
    • 2021-03-08
    • 2017-04-18
    • 2019-07-08
    • 2019-09-20
    • 2016-01-05
    • 1970-01-01
    • 1970-01-01
    • 2014-08-05
    相关资源
    最近更新 更多