Laravel 5 我想在laravel中为我的评论提交按钮提供功能,我想将评论保存到数据库,并在视图中显示最新的评论。

Laravel 5 我想在laravel中为我的评论提交按钮提供功能,我想将评论保存到数据库,并在视图中显示最新的评论。,laravel-5,Laravel 5,我已经创建了一个文本区域和一个提交按钮,它们可以在视图上看到,但不起作用。我想在我的帖子下面添加评论,并想把评论保存在我在mysql中创建的数据库中,我制作了一个commentController,我不确定里面有什么代码 <?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\post; use App\comment; use Auth; class commentControll

我已经创建了一个文本区域和一个提交按钮,它们可以在视图上看到,但不起作用。我想在我的帖子下面添加评论,并想把评论保存在我在mysql中创建的数据库中,我制作了一个commentController,我不确定里面有什么代码

    <?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\post;
use App\comment;
use Auth;

class commentController extends Controller
{
    public function index(post $post)
    {
        return response()->json($post->comments()->with('user')->latest()->get());
    }

    public function store(Request $request, post $post)
    {
        $comment = $post->comments()->create([
            'body' => $request->body,
            'user_id' => Auth::id()
        ]); 

        $comment = comment::where('id', $comment->id)->with('user')->first();

        return $comment->toJson();
    }
}

我已经编写了一个ajax代码,我正在提交下面的代码,请帮助我改进代码。$('document').ready(function(){var flag=0;$('.comment').on('click',function(){var id=$(this).data(“id”);$.ajax({type:'POST',url:'/comments',data:{id:POST_id,flag:user_id},我将post_id、user_id、author、body作为comments表的属性(列)。