In this tutorial, we will learn How to use Google Charts in Laravel 8

Step 1: 

Install Laravel 

composer create-project --prefer-dist laravel/laravel blogFirebase

Step 2: 

Create Migration and Model 

php artisan make:migration create_visitor_table

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateVisitorTable extends Migration
     * Run the migrations.
     * @return void
    public function up()
        Schema::create('visitors', function (Blueprint $table) {
     * Reverse the migrations.
     * @return void
    public function down()

 create model using bellow command:

php artisan make:model Visitor


namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Visitor extends Model
    use HasFactory;

Step 3: 

Add Route routes/web.php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\HomeController;
| Web Routes
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
Route::get('google-line-chart', [HomeController::class, 'googleLineChart']);

Step 4: 

Create Controller app/Http/Controllers/HomeController.php

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Visitor;
use DB;
class HomeController extends Controller
     * Create a new controller instance.
     * @return void
    public function googleLineChart()
        $visitor = Visitor::select(
                        DB::raw("year(created_at) as year"),
                        DB::raw("SUM(click) as total_click"),
                        DB::raw("SUM(viewer) as total_viewer")) 
        $result[] = ['Year','Click','Viewer'];
        foreach ($visitor as $key => $value) {
            $result[++$key] = [$value->year, (int)$value->total_click, (int)$value->total_viewer];
        return view('google-line-chart')

Step 5: 

Create View File resources/view/google-line-chart.blade.php

    <script type="text/javascript" src=""></script>
    <script type="text/javascript">
      var visitor = <?php echo $visitor; ?>;
      google.charts.load('current', {'packages':['corechart']});
      function drawChart() {
        var data = google.visualization.arrayToDataTable(visitor);
        var options = {
          title: 'Site Visitor Line Chart',
          curveType: 'function',
          legend: { position: 'bottom' }
        var chart = new google.visualization.LineChart(document.getElementById('linechart'));
        chart.draw(data, options);
    <h1>Laravel Google Chart Example -</h1>
    <div id="linechart" style="width: 900px; height: 500px"></div>

May this example help you.