doubei8541 2015-09-26 05:18
浏览 90
已采纳

Laravel 5 json响应数组

I followed a tutorial on Laravel and AngularJS and trying to convert a public function to laravel 5. The code is this:

public function store()
    {
        Comment::create(array(
            'author' => Input::get('author'),
            'text' => Input::get('text')
        ));

        return Response::json(array('success' => true));
    }

I converted it with this:

public function store()
    {
        Comment::create(array(
            'author' => Request::get('author'),
            'text' => Request::get('text')
        ));
    }

Now, how about the line return Response::json(array('success' => true))? How can I convert it to Laravel 5? Thank you.

  • 写回答

1条回答 默认 最新

  • duanqiu9104 2015-09-26 05:28
    关注

    Not sure what you mean by converting to Laravel 5, this line of code itself is valid Laravel 5 code, but you can leverage nice helper function Laravel 5 provides:

    return response()->json([
        'success' => true
    ]);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 shape_predictor_68_face_landmarks.dat
  • ¥15 slam rangenet++配置
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题