<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Log;

class LogController extends Controller
{
    //
    public function read(Request $request)
    {
        try {
            // 從請求中獲取專案編號
            $project_number = $request->input('project_number');

            // 根據專案編號查詢Log資料
            $logs = Log::where('project_number', $project_number)->get();

            // 回傳Log資料
            return response()->json($logs);
        } catch (\Exception $e) {
            // 捕捉錯誤並回傳錯誤訊息
            return response()->json(['error' => 'Failed to retrieve logs', 'message' => $e->getMessage()], 500);
        }
    }
}
