php - Undefined variable: sales_chart (Laravel Chart)
问题描述
I'm a beginner in php and in Laravel. I wanted to add charts to my dashboard. The charts can be displayed on a new separate page but when I include it to my dashboard, it gives me an
error Undefined variable: sales_chart (View: C:\xampp\htdocs\Laravel\microelephant_updated~\microelephant\resources\views\chart.blade.php)
This is what's in my chart.blade.php
<div class='flex'>
<div class="w-1/2">
{!! $sales_chart-> container() !!}
</div>
{!! $sales_chart-> script() !!}
</div>
My ChartController
namespace App\Http\Controllers;
use App\Invoice;
use Illuminate\Http\Request;
use App\Charts\SalesChart;
class ChartController extends Controller
{
public function index(Request $request)
{
$sales = Invoice::orderBy('created_at')->pluck('total','created_at');
$sales_chart = new SalesChart;
$sales_chart->labels($sales->keys());
$sales_chart->dataset('Sales', 'line', $sales->values());
return view('chart', compact('sales_chart'));
}
}
How I include the chart in my dashboard
<div class="main-content">
@include('chart')
</div>
This is my Route
Route::get('/chart', 'ChartController@index');
There is something wrong with my code but I don't know where it is. Please help :(
解决方案
推荐阅读
- javascript - 如何在 ng-repeat 中删除/添加 html 标签
- makefile - Makefile - 检查空环境变量的函数
- mysql - 如何格式化看起来像这样的日期(20200326)MYSQL
- r - R:可变长度在 Wilcoxon 测试中不同
- python - fastavro - 将 json 文件转换为 avro 文件
- matlab - MATLAB:在 cellfun 中使用 get 获取对象元胞数组
- html - 使用 vba 从数据提示中的 div 中抓取元素
- python-3.x - 如何迭代 WebElements 并在 Robot Framework 中获取新的 WebElement
- oauth-2.0 - Pinterest API - 授权失败
- java - 从 IntelliJ 中的 Java SparkContext 访问 JavaPairRDD 中的第一个元素时出错