Php 方法Illumb\View\View::\uu toString()-类stdClass的对象无法转换为字符串
我用laravel 5.3和 我想制作一个图表,我希望它是动态的,标签字段是用户参与其任务的项目的标题数组(希望我清楚) 直到现在我才有这样的东西Php 方法Illumb\View\View::\uu toString()-类stdClass的对象无法转换为字符串,php,charts,laravel-5.3,Php,Charts,Laravel 5.3,我用laravel 5.3和 我想制作一个图表,我希望它是动态的,标签字段是用户参与其任务的项目的标题数组(希望我清楚) 直到现在我才有这样的东西 $idUser = Auth::user()->id; $tasksUsed = DB::table('user_task') ->join('tasks', 'tasks.id', '=', 'user_task.task_id') ->join('projects
$idUser = Auth::user()->id;
$tasksUsed = DB::table('user_task')
->join('tasks', 'tasks.id', '=', 'user_task.task_id')
->join('projects', 'projects.id', '=', 'tasks.project_id')
->select('projects.title')->where('user_task.user_id',$idUser)->get();
// dd($tasksUsed->toArray());
$chart = Charts::create('donut', 'morris')
// ->view('custom.line.chart.view') // Use this if you want to use your own template
->title('My nice chart')
->labels($tasksUsed->toArray())
->values([3,4])
->dimensions(300,300)
->responsive(false);
它给了我这个错误,我不知道如何解决它
Method Illuminate\View\View::__toString() must not throw an exception, caught ErrorException: Object of class stdClass could not be converted to string
...\vendor\consoletvs\charts\resources\views\morris\donut.blade.php)
我认为在您的
donut.blade.php
中,您正在做这样的事情:
{!! $chart !!}
由于$chart
是一个对象,因此不能将其打印为字符串
$chart = Charts::create('donut', 'morris')
// ->view('custom.line.chart.view') // Use this if you want to use your own template
->title('My nice chart')
->labels($tasksUsed->pluck('title')->toArray())
->values([3,4])
->dimensions(300,300)
->responsive(false);
这就是解决方案在我看来,我这样做:{!!$chart->render()!!}非常接近。检查该库的文档,因为
$chart->render()
正在返回一个对象。