use App\Http\Controllers\Controller;
use App\Charts\AgorakitChart;
class InsightsController extends Controller
{
public function index()
{
$chart = new AgorakitChart;
$chart->title('General stats');
$chart->labels(['Groups', 'Active groups', 'Users', 'Verified users', 'Active users', 'Discussions', 'Comments', 'Events', 'Files']);
$chart->dataset('Amount', 'bar', [
\App\Group::count(),
\App\Group::active()->count(),
\App\User::count(),
\App\User::verified()->count(),
\App\User::active()->verified()->count(),
\App\Discussion::count(),
\App\Comment::count(),
\App\Action::count(),
\App\File::count()
]);
$charts[] = $chart;
$results = \App\Discussion::selectRaw('year(created_at) year, extract(YEAR_MONTH FROM created_at) AS yearmonth, monthname(created_at) month, count(*) data')
->groupBy('yearmonth')
->orderBy('yearmonth', 'asc')
->get();
$dataset = [];
$labels = [];
foreach ($results as $result) {
$dataset[] = $result->data;
$labels[] = $result->year . ' / ' . $result->month;
}
$chart = new AgorakitChart;
$chart->title('Discussions per month');
$chart->labels($labels);
$chart->dataset('Amount', 'line', $dataset);
$charts[] = $chart;
//
}
}