Problems with Laravel Charts, always class error not found!

Asked

Viewed 54 times

0

Gentlemen, I’m using the Laravel 5.7 and the following problem

Class 'ConsoleTVs\Charts\Facades\Charts' not found 

I did his installation correctly:

composer require consoletvs/charts

added in the config/app.php

'providers' => [
    ....
    ....
    ConsoleTVs\Charts\ChartsServiceProvider::class,
],
'aliases' => [
    ....
    ....
    'Charts' => ConsoleTVs\Charts\Facades\Charts::class,
],

I created the model and Controller necessary

$products = Product::where(DB::raw("(DATE_FORMAT(created_at,'%Y'))"),date('Y'))->get();
    $chart = Charts::database($products, 'bar', 'highcharts')
              ->title("Product Details")
              ->elementLabel("Total Products")
              ->dimensions(1000, 500)
              ->responsive(true)
              ->groupByMonth(date('Y'), true);


    $pie_chart = Charts::create('pie', 'highcharts')
            ->title('Pie Chart Demo')
            ->labels(['Product 1', 'Product 2', 'Product 3'])
            ->values([15,25,50])
            ->dimensions(1000,500)
            ->responsive(true);

and in my View

{!! $chart->render() !!}

Where can I be missing?

  • You turned the remote php artisan vendor:publish --tag=charts_config?

  • Yes rodei yes @sant0will

1 answer

0

As you are setting the way for the full class, add \ at first.

More information here: http://php.net/manual/en/language.namespaces.faq.php#language.namespaces.Faq.Qualified

If you don’t put the bar at the beginning, it will take the current namespace and try to find it (e.g.: If it’s in "App", it will turn: "App Console...").

<?php
//....
'providers' => [
    ....
    ....
    \ConsoleTVs\Charts\ChartsServiceProvider::class,
],
'aliases' => [
    ....
    ....
    'Charts' => \ConsoleTVs\Charts\Facades\Charts::class,
],

Browser other questions tagged

You are not signed in. Login or sign up in order to post.