ispt4.0_laravel/app/Http/ViewComposers/WorkstationComposer.php
2024-01-25 16:54:19 +00:00

46 lines
1.5 KiB
PHP
Executable File

<?php
namespace App\Http\ViewComposers;
use App\Models\ConstructionWorkstation;
use App\Models\ControlEquipmentWorkstation;
use App\Models\Equipment;
use App\Models\EquipmentWorkHistory;
use App\Models\User;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\View\View;
class WorkstationComposer
{
public function compose(View $view)
{
$userEmail = Auth::user()->email;
$receiveDataEmail = User::where('email', $userEmail)->first();
$receiveDataWs = ConstructionWorkstation::where('name_workstations', $receiveDataEmail->user_name)->first();
$receiveAllEquipmentOfProject = Equipment::where('company_projects_id', $receiveDataWs->company_projects_id)
->whereHas('equipmentWorkHistory', function ($query) use ($receiveDataWs) {
$query->where('company_projects_id', $receiveDataWs->company_projects_id);
})
->whereDoesntHave('equipmentWorkHistory.controlEquipmentWorkstation', function ($query) {
$query->whereNull('elemental_tasks_id')
->whereNull('departure_date');
})
->get();
$receiceCountAllEquipmentOfProject = count($receiveAllEquipmentOfProject);
//Returning values of the queries to workstations layout
$view->with([
'receiveAllEquipmentOfProject' => $receiveAllEquipmentOfProject,
'receiceCountAllEquipmentOfProject' => $receiceCountAllEquipmentOfProject,
'receiveDataWs' => $receiveDataWs,
]);
}
}