42 lines
1.1 KiB
PHP
42 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\APIS\CustomerApi;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\User;
|
|
use App\Models\UserAssetLink;
|
|
use Illuminate\Http\Request;
|
|
use Tymon\JWTAuth\Facades\JWTAuth;
|
|
use Illuminate\Container\Attributes\Auth;
|
|
use Illuminate\Database\QueryException;
|
|
use Illuminate\Support\Facades\Log;
|
|
class UserAssetLinkController extends Controller
|
|
{
|
|
|
|
public function index()
|
|
{
|
|
|
|
$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);
|
|
}
|
|
|
|
|
|
}
|