Skip to content

Latest commit

 

History

History
48 lines (39 loc) · 1.83 KB

readme.md

File metadata and controls

48 lines (39 loc) · 1.83 KB

Packagist PHP Version Support Packagist Version Packagist Downloads

About

blumilksoftware\laravel-heatmap is an extension of blumilksoftware\heatmap allowing you to use heatmap with Model data from Laravel Eloquent.

Installation

The Laravel Heatmap is distributed as Composer library via Packagist. To add it to your project, just run:

composer require blumilksoftware/laravel-heatmap

Usage

Creating a heatmap from Laravel Collection

You can build a heatmap directly from collection of Eloquent models:

use Blumilk\LaravelHeatmap\LaravelHeatmapBuilder;
use App\Models\YourModel;

$data = YourModel::all(); // Assuming YourModel has a 'created_at' field

$heatmapBuilder = new LaravelHeatmapBuilder();
$heatmap = $heatmapBuilder->buildFromCollection($data, 'created_at');

You can also build heatmap from array:

use Blumilk\LaravelHeatmap\LaravelHeatmapBuilder;

$data = [
    ["created_at" => "2022-11-01 00:00:00"],
    ["created_at" => "2022-11-03 00:00:00"],
    ["created_at" => "2022-11-16 00:00:00"],
    ["created_at" => "2022-11-16 00:00:00"],
    ["created_at" => "2022-11-18 00:00:00"],
    ["created_at" => "2022-11-19 00:00:00"],
];

$heatmapBuilder = new LaravelHeatmapBuilder();
$heatmap = $heatmapBuilder->buildFromArray($data, 'created_at');

There is also option to build from query:

use Blumilk\LaravelHeatmap\LaravelHeatmapBuilder;

$query = YourModel::where('created_at', '>', '2022-11-01 00:00:00');

$heatmapBuilder = new LaravelHeatmapBuilder();
$heatmap = $heatmapBuilder->buildFromQuery($query, 'created_at');