在我的 Laravel 版本 5.5.22 安装 ConsoleTVs/Charts Composer 包时,我收到此错误,调用未定义的方法 ConsoleTVs\Charts\Builder::new()。我正确地遵循了教程,我没有看到任何出错的部分,我什至使用转储自动加载但没有任何反应。有谁能够帮助我?提前致谢
这是我点击的链接: https://devhub.io/zh/repos/ConsoleTVs-Charts#pie
测试 Controller :
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use Charts;
class PieController extends Controller
{
public function index()
{
$chart = Charts::new('line', 'highcharts')
->setTitle('My nice chart')
->setLabels(['First', 'Second', 'Third'])
->setValues([5,10,20])
->setDimensions(1000,500)
->setResponsive(false);
return view('pie', ['chart' => $chart]);
}
}
配置/app.php
Providers:
ConsoleTVs\Charts\ChartsServiceProvider::class,
Aliases:
'Charts' => ConsoleTVs\Charts\Charts::class,
or
'Charts' => ConsoleTVs\Charts\Facades\Charts::class,
pie.blade.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>My Charts</title>
{!! Charts::assets() !!}
</head>
<body>
<center>
{!! $chart->render() !!}
</center>
</body>
</html>
最佳答案
正如您的问题一样,您需要删除 setTitle()
并将其更改为 title()
,因为这在新版本中发生了变化!
Charts::new
必须更改为 Charts::create
,因为新版本中不存在 new
方法。如果您想从数据库获取数据,还有 Charts::database
(更多信息请参见此链接:https://hdtuto.com/article/laravel-5-chart-example-using-charts-package)
安装后需要运行以下命令:
php artisan cache:clear
php artisan config:clear
php artisan config:cache
如果您仍然遇到任何错误,请点击此链接并执行其中提供的步骤!:https://github.com/ConsoleTVs/Charts/issues/13
希望这能解决您的问题!
关于php - 调用未定义的方法 ConsoleTVs\Charts\Builder::new() laravel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47546786/