2025-03-11 17:15:41 +05:30
|
|
|
<?php
|
|
|
|
|
|
2025-03-11 17:52:55 +05:30
|
|
|
namespace App\Http\Controllers\APIS\CustomerApi;
|
2025-03-11 17:15:41 +05:30
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
2025-03-11 17:52:55 +05:30
|
|
|
use App\Models\User;
|
2025-03-11 17:15:41 +05:30
|
|
|
use App\Models\UserAssetLink;
|
|
|
|
|
use Illuminate\Http\Request;
|
2025-03-11 19:44:37 +05:30
|
|
|
use Tymon\JWTAuth\Facades\JWTAuth;
|
2025-03-12 19:19:13 +05:30
|
|
|
use Illuminate\Container\Attributes\Auth;
|
|
|
|
|
use Illuminate\Database\QueryException;
|
|
|
|
|
use Illuminate\Support\Facades\Log;
|
2025-03-11 17:15:41 +05:30
|
|
|
class UserAssetLinkController extends Controller
|
|
|
|
|
{
|
2025-03-12 19:19:13 +05:30
|
|
|
|
2025-03-11 17:15:41 +05:30
|
|
|
public function index()
|
|
|
|
|
{
|
2025-03-18 15:45:21 +05:30
|
|
|
|
|
|
|
|
$token = readHeaderToken();
|
|
|
|
|
|
|
|
|
|
$user = User::with(['assets.devices'])
|
|
|
|
|
->withCount([
|
|
|
|
|
'assets as active_devices_count' => function ($query) {
|
|
|
|
|
$query->whereHas('devices', function ($q) {
|
|
|
|
|
$q->where('active', 1);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
'assets as inactive_devices_count' => function ($query) {
|
|
|
|
|
$query->whereHas('devices', function ($q) {
|
|
|
|
|
$q->where('active', 0);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
])
|
|
|
|
|
->where('id', $token['sub'])
|
|
|
|
|
->first();
|
|
|
|
|
|
|
|
|
|
return response()->json($user);
|
2025-03-11 17:15:41 +05:30
|
|
|
}
|
2025-03-18 15:45:21 +05:30
|
|
|
|
|
|
|
|
|
2025-03-11 19:05:25 +05:30
|
|
|
}
|