Laravel评论系统

时间:2016-01-24 02:33:43

标签: php ajax laravel-5

我目前正在Laravel 5中开发一个评论功能。我想立即显示用户发布的评论。那我怎么能实现呢?我曾尝试在AJAX中使用s.sku_analytics.all方法,但它仍然不起作用。

以下是插入评论的控制器:

load()

以下是视图和使用ORM获取用户名的public function newComment(Request $request) { try { $date_format = date('Y-m-d'); $comment=new Comment(); $comment->user_id=Auth::user()->id; $comment->introduce=$request->introduce; $comment->completed_day=$request->completed_day; $comment->allowance=str_replace( ',', '', $request->allowance); $comment->post_at=$date_format; $comment->job_id=$request->job_id; $comment->save(); return response()->json(array('mess'=>'Success')); } catch (Exception $ex) { return response()->json(array('err'=>'Error')); } } 即时消息

{{$jobReply -> user -> full_name }}

这是插入评论的AJAX:

<div class="panel-body"  id="job_comment_post" style="text-align:left">
    <table class="table table-hover"> 
        <thead> 
            <tr> 
                <th>Freelancer name</th> 
                <th>Introduce</th> 
                <th>Completed day</th> 
                <th>Allowance</th> 
            </tr> 
        </thead> 
        <tbody> 
            @foreach($job_comment as $jobReply)
                <tr> 
                    <td>{{$jobReply -> user -> full_name }}</td> 
                    <td>{{$jobReply -> introduce}}</td>
                    <td>{{$jobReply -> completed_day}}</td>
                    <td>{{number_format($jobReply -> allowance)}}</td>
                </tr> 
            @endforeach()
        </tbody> 
    </table>

    <div class="details_pagi">
        {!! $job_comment->render() !!}
    </div>                      
</div>

0 个答案:

没有答案