如何从另一个数据库连接(.env 文件中的“mysql2”)在 laravel 中生成一个图表,可能是饼图或圆环图?我知道如何从主数据库生成图表。但是这次我没有迁移第二个数据库,因为它已经有表和数据了。我可以使用“dd”命令获取数据,但是如果我在其中生成图表则是另一回事。请帮我做作业。这是我的HomeController.php<?phpnamespace App\Http\Controllers;use Illuminate\Http\Request;use App\User;use Illuminate\Support\Facades\DB;use Charts;class HomeController extends Controller{ /** * Create a new controller instance. * * @return void */ public function __construct() { $this->middleware('auth'); } /** * Show the application dashboard. * * @return \Illuminate\Contracts\Support\Renderable */ public function index() { // // $count = User::count(); $chart = Charts::database(User::all(),'line','highcharts') ->title('User Statistics') ->groupByYear(7) ->Width(0) ->ElementLabel('Total Users Registered') ->Responsive(true); return view('dashboard',['chart'=>$chart])->with('count', $count); // return view('dashboard', ['chart' => $chart]); // $count = User::count(); // return View::make('dashboard')->with('count', $count); // return view('dashboard'); } public function logout () { //logout user auth()->logout(); // redirect to homepage return redirect('/coindeoro'); } //FETCH DATA FROM THE SECOND DATABASE public function another(){ // $arr_graph = \DB::connection('mysql2')->select("SELECT * FROM ico_stages WHERE id = ?", [1]); $arr_graph = \DB::connection('mysql2')->select("SELECT * FROM ico_stages WHERE id = ?", [1]); //DISPLAY dd($arr_graph); }}
2 回答
- 2 回答
- 0 关注
- 170 浏览
添加回答
举报
0/150
提交
取消