Download the PHP package mohammad-zarifiyan/laravel-chart without Composer
On this page you can find all versions of the php package mohammad-zarifiyan/laravel-chart. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mohammad-zarifiyan/laravel-chart
More information about mohammad-zarifiyan/laravel-chart
Files in mohammad-zarifiyan/laravel-chart
Package laravel-chart
Short Description A Laravel package that helps you to quickly create charts from database.
License
Informations about the package laravel-chart
Laravel Chart
This Laravel package helps you to export data for charts using Eloquent ORM easily.
Installation
To install package, just run the following command in the root of your project:
Implementation
First you need to give trait MohammadZarifiyan\LaravelChart\Traits\HasChart to your model.
Then use the exportForChart method to extract the data.
- The first parameter of this method must be an instance of
Carbon\CarbonPeriodthat specifies the beginning and end of the total time period. - The second parameter of this method must be a closure that its first parameter is an instance of
Illuminate\Database\Eloquent\Builderand its second parameter is an instance ofCarbon\CarbonPeriod. In this closure, you must apply conditions to theIlluminate\Database\Eloquent\Builderthat limit the data to the time period given byCarbon\CarbonPeriodand 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
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.
Above code output will be something like this:
You can also filter the table data based on a column in a relation. In the example below, we get the sum of the invoices amount based on their payment time.