<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class WeightController extends Controller
{
    public function store(Request $request)
{
    file_put_contents(storage_path('weight.txt'), $request->weight);

    return response()->json(['status' => 'ok']);
}

    public function latest()
    {
        $data = DB::table('weights')
            ->orderBy('id', 'desc')
            ->first();

        return response()->json([
            'weight' => $data->weight ?? 0
        ]);
    }
    
    public function getLiveWeight()
{
    $weight = file_get_contents(storage_path('weight.txt'));

    return response()->json([
        'weight' => $weight
    ]);
}
}