Laravel 5的数据表包,Parse作为数据源

时间:2022-08-29 14:26:00

I am using Laravel 5, Datatables jQuery plugin and Datatables package for handling the server side requests.

我正在使用Laravel 5,Datatables jQuery插件和Datatables包来处理服务器端请求。

Everything works great if I use Eloquent. The problem is my application needs to get the data from Parse.com using it's PHP SDK. Is there a way to make the Datatables package work if I pass to it's of method an array that contains the data I need to display?

如果我使用Eloquent,一切都很好。问题是我的应用程序需要使用它的PHP SDK从Parse.com获取数据。有没有办法让Datatables包工作,如果我传递给它的方法一个包含我需要显示的数据的数组?

a working example is:

一个工作的例子是:

$users = User::select(['name','email']);
return Datatables::of($users)->make();

what I would need would be:

我需要的是:

$users = array(['name' => 'John Doe', 'email' => 'john@email.com'], 
               ['name' => 'Robert Roe', 'email' => 'robert@email.com']);

return Datatables::of($users)->make();

1 个解决方案

#1


As of v5.x of Datatables package, It is now possible to pass a Collection as a data source.

从Datatables包的v5.x开始,现在可以将Collection作为数据源传递。

$data = array(['name' => 'John Doe', 'email' => 'john@email.com'], 
               ['name' => 'Robert Roe', 'email' => 'robert@email.com']);
$users = new Collection($data);

return Datatables::of($users)->make();

#1


As of v5.x of Datatables package, It is now possible to pass a Collection as a data source.

从Datatables包的v5.x开始,现在可以将Collection作为数据源传递。

$data = array(['name' => 'John Doe', 'email' => 'john@email.com'], 
               ['name' => 'Robert Roe', 'email' => 'robert@email.com']);
$users = new Collection($data);

return Datatables::of($users)->make();