欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

控制器中返回 json 有大用

shiping1 的头像

public function updateSort(SortPermissionGroupRequest $request)

{
    $this->groups->updateSort($request->get('data'));
    return response()->json(['status' => 'OK']);
}


public function index($postId)

{
    $post = PostRepository::find($postId, ['id']);
    if (!$post) {
        Session::flash('error', 'The post you were viewing has been deleted.');

        return Response::json([
            'success' => false,
            'code'    => 404,
            'msg'     => 'The post you were viewing has been deleted.',
            'url'     => URL::route('blog.posts.index'),
        ], 404);
    }

    $comments = $post->comments()->get(['id', 'version']);

    $data = [];

    foreach ($comments as $comment) {
        $data[] = ['comment_id' => $comment->id, 'comment_ver' => $comment->version];
    }

    return Response::json(array_reverse($data));
}

普通分类: