24 lines
675 B
PHP
24 lines
675 B
PHP
<?php
|
|
use App\Models\SensorData;
|
|
|
|
function getDevices($all = false)
|
|
{
|
|
$user = Auth::user();
|
|
$data = SensorData::select('device_name')->distinct()->get();
|
|
$filteredData = [];
|
|
foreach ($data as $item) {
|
|
$deviceName = @explode('_', $item->device_name)[0];
|
|
$deviceName = strtolower($deviceName);
|
|
|
|
if (!in_array($deviceName, $filteredData)) {
|
|
if ($all) {
|
|
$filteredData[] = $deviceName;
|
|
} else {
|
|
if (in_array($deviceName, $user->unit?->device_names ?? [])) {
|
|
$filteredData[] = $deviceName;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return $filteredData;
|
|
} |