ppranav / table-insights
TableInsights 是一个专门为使用 Laravel 框架的后端开发者设计的强大包。它允许使用模型轻松地将数据库表转换为有意义的统计信息和洞察。
1.6
2023-02-01 18:01 UTC
README
TableInsights 是一个专门为使用 Laravel 框架的后端开发者设计的强大包。它允许使用模型轻松地将数据库表转换为有意义的统计信息和洞察。
入门
先决条件
- Laravel 框架
安装
您可以通过 composer 安装此包
composer require ppranav/table-insights
您可以通过运行以下命令来加载包的配置文件
php artisan vendor:publish --tag=tableinsights
配置文件允许您自定义 tableinsights 的设置。
您可以根据需要自定义 Tableinsights 数组的键名,并启用或禁用单个键。要更改键名,请在右侧字段中输入/替换所需的键名。
用法
在您的类中扩展 \Ppranav\TableInsights\TableInsights 类,并在以下代码中实现 models() 方法
/** * Add arrays of models * @return array<Model, string> */ public function models() { return [ Project::class => 'created_at', TaskLog::class => 'committed_at' ]; }
您还可以使用以下代码更新 models 查询
public function setQuery(Activity $activity) { return $activity->query()->where(‘user_id’, auth()->id()); }
最后,您的实现类应如下所示
class Dashboard extends TableInsights { /** * Add arrays of models * @return array<Model, string> */ public function models() { return [ Project::class => 'created_at', TaskLog::class => 'committed_at' ]; } public function setQuery(Activity $activity) { return $activity->query()->where('created_for_id', auth()->id()); } }
在控制器中显示洞察
return (new Dashboard())->getInsights();