Laravel的数据表服务器端php类 [英] Datatable server side php class for laravel
本文介绍了Laravel的数据表服务器端php类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要引用此示例.
但是,此示例中给出的服务器端php类"ssp.class.php"使用带有原始sql的核心php,我不能将其直接用于laravel项目.有没有人参考laravel方式做数据表.我暂时不想使用任何软件包.
However, the server side php class "ssp.class.php" given in this example uses core php with raw sql, I can not use it directly for laravel projects. Does anyone has reference to laravel way doing datatables. I don't want to use any packages at the moment though.
推荐答案
您可以使用syamsoul/laravel-datatable-ssp
包..
- 打开CLI并输入您的应用目录
- 运行此命令
composer require syamsoul/laravel-datatable-ssp
-
在您的控制器中,需要添加
use SoulDoit\DataTable\SSP;
,您可以按照以下代码进行操作:
- Open CLI and enter your app directory
- Run this command
composer require syamsoul/laravel-datatable-ssp
In your controller, need to add
use SoulDoit\DataTable\SSP;
, and you can follow the code below:
public function get(){
$dt = [
['db'=>'id', 'dt'=>0, 'formatter'=>function($value, $model){ return str_pad($value, 8, '0', STR_PAD_LEFT); }],
['db'=>'email', 'dt'=>1],
['db'=>'first_name', 'dt'=>2, 'formatter'=>function($value, $model){ return $value . ' ' . $model->last_name; }],
['db'=>'created_at', 'dt'=>3],
['db'=>'email_verified_at'],
['db'=>'last_name'], // must include this because need to re-use in 'first_name' formatter
];
$dt_obj = new SSP('\App\User', $dt);
$dt_arr = $dt_obj->getDtArr();
return response()->json($dt_arr);
}
这在Laravel 5.8
上运行得很好...我不确定其他版本.
This is working perfectly on Laravel 5.8
... I'm not sure about the other versions.
这篇关于Laravel的数据表服务器端php类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文