Я пытаюсь создать приложение laravel, где линейный график отображает уровень сахара в крови вошедшего в систему пользователя, который соответствует определенному дню. Я сейчас использую пакет ConsoleTV, но открыта для других опций.
Я пробовал пару разных запросов, но, похоже, я не могу получить их, чтобы показать, что именно я хочу. На оси Y вместо того, чтобы показывать уровень сахара в крови, он просто подсчитывает количество записей за этот день.
Мой контроллер:
public function chart()
{
// $bloodSugar = BloodSugar::where(\DB::raw("(DATE_FORMAT(created_at,'%D'))"),date('D'))->where('user_id', Auth::id())->get();
$bloodSugar = BloodSugar::where('user_id', Auth::id())->get();
$chart = Charts::database($bloodSugar, 'line', 'highcharts')
->title('Blood Sugars')
->elementLabel('Blood Sugar Level')
->groupByDay();
return view ('bloodsugars.index', compact('chart'));
}
Моя модель пользователя
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
public function reviews()
{
return $this->hasMany(BloodSugar::class);
}
}
Модель сахара в крови
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class BloodSugar extends Model
{
protected $fillable = ['date', 'time', 'blood_sugar_level', 'scenario', 'user_id'];
public function user()
{
return $this->belongsTo(User::class);
}
}
Таблица базы данных моих пользователей
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->string('email')->nullable();
$table->date('dob')->nullable();
$table->string('diabetic_type')->nullable();
$table->string('other_info')->nullable();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->string('provider')->nullable();
$table->string('provider_id')->nullable();
$table->rememberToken();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('users');
}
}
Таблица сахара в крови
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateBloodSugarsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('blood_sugars', function (Blueprint $table) {
$table->increments('id');
$table->date('date');
$table->time('time');
$table->double('blood_sugar_level');
$table->text('scenario');
$table->integer('user_id');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('blood_sugars');
}
}
Мой график в настоящее время выводит количество сахара в крови, записанного за этот день, а не фактический уровень сахара в крови.