dev
Jing Li 2023-08-02 22:31:51 +08:00
parent 025cea099e
commit 7820f01b32
2 changed files with 59 additions and 0 deletions

View File

@ -0,0 +1,22 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class DeviceLog extends Model
{
use HasFactory;
protected $casts = [
'data' => 'json',
'reported_at' => 'datetime',
];
protected $fillable = [
'device_id',
'data',
'reported_at',
];
}

View File

@ -0,0 +1,37 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('device_logs', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('device_id');
$table->json('data')->nullable();
$table->timestamp('reported_at');
$table->timestamps();
$table->index(['device_id', 'reported_at']);
$table->index('reported_at');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('device_logs');
}
};