API Charts
This is the official documentation of the forestadmin/laravel-forestadmin
v2+ and forestadmin/symfony-forestadmin
PHP agents.
API charts in the legacy agents were declared using routes.
In the new agent, you will need to use either the agent.addChart
or the collection.addChart
function, depending on if the chart is to be displayed on a record of a collection or a dashboard.
Code cheatsheet
route in web.php
$agent->addChart collection.addChart(...)
render Chart
return $resultBuilder->value(...) return $resultBuilder->distribution(...)
request object
$context->recordId
How to migrate
Migrating should be straightforward: the only differences are that:
dashboard charts are now declared using the
agent.addChart
function.collection charts are now declared using the
collection.addChart
function, and access the record id usingcontext.recordId
instead ofrequest.query?.record_id
.Both types should use the
resultBuilder
helper to return the chart data.
Define a new route in
web.php
:Setup an action into a controller
<?php
namespace App\Http\Controllers;
use ForestAdmin\LaravelForestAdmin\Facades\ChartApi;
use Stripe\StripeClient;
class ChartsController extends Controller
{
public function mrr()
{
$mrr = 0;
$stripe = new StripeClient('sk_AABBCCDD11223344');
$charges = $stripe->charges->all(['limit' => 3]);
foreach ($charges as $charge) {
$mrr += $charge->amount;
}
return ChartApi::renderValue($mrr);
}
}
Last updated
Was this helpful?