如何使用 return 分页为 json laravel
How to paginate with return as json laravel
我想用 return 创建分页 json,但我收到如下错误
ErrorException in Macroable.php line 74:
Method links does not exist.
这里是我的控制器代码
public function getcustomer($id){
$customer = Customer::find($id)->paginate(5);
return response()->json([$customer], 200);
}
这是我的 blade 代码
{{$customer->links('vendor.pagination.pagination')}}
如何使用 json response() 创建分页?
The Laravel paginator result classes implement the Illuminate\Contracts\Support\Jsonable
Interface contract and expose the toJson
method, so it's very easy to convert your pagination results to JSON.
https://laravel.com/docs/5.3/pagination#converting-results-to-json
如果您想建立链接,您应该手动进行。或者你应该像往常一样 return 分页并使用 render()
方法来构建链接并创建分页对象的副本以将其转换为 JSON with toJson()
.
我想用 return 创建分页 json,但我收到如下错误
ErrorException in Macroable.php line 74: Method links does not exist.
这里是我的控制器代码
public function getcustomer($id){
$customer = Customer::find($id)->paginate(5);
return response()->json([$customer], 200);
}
这是我的 blade 代码
{{$customer->links('vendor.pagination.pagination')}}
如何使用 json response() 创建分页?
The Laravel paginator result classes implement the
Illuminate\Contracts\Support\Jsonable
Interface contract and expose thetoJson
method, so it's very easy to convert your pagination results to JSON.
https://laravel.com/docs/5.3/pagination#converting-results-to-json
如果您想建立链接,您应该手动进行。或者你应该像往常一样 return 分页并使用 render()
方法来构建链接并创建分页对象的副本以将其转换为 JSON with toJson()
.