PHPackages                             mohammad-zarifiyan/laravel-chart - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. mohammad-zarifiyan/laravel-chart

ActiveLibrary[Database &amp; ORM](/categories/database)

mohammad-zarifiyan/laravel-chart
================================

A Laravel package that helps you to quickly create charts from database.

3.0.1(2mo ago)339PHPPHP ^8

Since Apr 15Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/MohammadZarifiyan/Laravel-Chart)[ Packagist](https://packagist.org/packages/mohammad-zarifiyan/laravel-chart)[ RSS](/packages/mohammad-zarifiyan-laravel-chart/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (3)Used By (0)

Laravel Chart
=============

[](#laravel-chart)

This Laravel package helps you to export data for charts using Eloquent ORM easily.

Installation
------------

[](#installation)

To install package, just run the following command in the root of your project:

```
composer require mohammad-zarifiyan/laravel-chart:^3.0
```

Implementation
--------------

[](#implementation)

First you need to give trait `MohammadZarifiyan\LaravelChart\Traits\HasChart` to your model. Then use the `exportForChart` method to extract the data.

1. The first parameter of this method must be an instance of `Carbon\CarbonPeriod` that specifies the beginning and end of the total time period.
2. The second parameter of this method must be a closure that its first parameter is an instance of `Illuminate\Database\Eloquent\Builder` and its second parameter is an instance of `Carbon\CarbonPeriod`. In this closure, you must apply conditions to the `Illuminate\Database\Eloquent\Builder` that limit the data to the time period given by `Carbon\CarbonPeriod` and then return the desired data for your chart.

The result of `exportForChart` method is an instance of `Illuminate\Support\Collection` that includes the data you returned in the closure, so you can use them in your charts.

### Example

[](#example)

In the following example, we have calculated the sum of the `amount` column of the invoices at the end of **each day** in the period of **one week ago until now**.

```
