Laravel 6 ORM Time-out

  laravel, php

I have a problem when I loop the data, it will show 504 Gateway Time-out.

Timesheets table : 15,000 records

Employees Table: 400 records

Manpower Table: 100, 000 records.

If I get 3 tables in SQL just take 0.1ms. Any other solution for my case? Thanks All.

$timesheets = Timesheets::where('type', 'Overtime')

foreach ($timesheets as $key => $value) {
    if (!empty($employeesUuid = Employees::where('employees_number', $value->employees_id)->first()->employees_uuid)) {
        $date          = Carbon::parse($value->start_dt)->format('Y-m-d');

        $manpower = Manpower::with('pwra.purchaseOrder')
            ->where("employees_uuid", $employeesUuid)
            ->whereDate("register_date", $date)

Source: Ask PHP