Laravel 5 JSON响应阵列
问题描述:
我跟着上Laravel
和AngularJS
并试图一个public function
转换教程laravel 5.码是这样的:Laravel 5 JSON响应阵列
public function store()
{
Comment::create(array(
'author' => Input::get('author'),
'text' => Input::get('text')
));
return Response::json(array('success' => true));
}
我与此将它转换:
public function store()
{
Comment::create(array(
'author' => Request::get('author'),
'text' => Request::get('text')
));
}
现在,行return Response::json(array('success' => true))
怎么样?我怎样才能将它转换成Laravel 5?谢谢。
答
不知道你的转换为Laravel 5的意思,这行代码本身是有效的Laravel 5码,但是你可以利用不错的辅助函数Laravel 5条规定:
return response()->json([
'success' => true
]);
在laravel 5,如果你只是返回一个数组它将在输出中显示为json,所以只需返回数组('success'=> true);会做。 – coderkane