Lae/app/Http/Controllers/Admin/DeviceController.php

54 lines
1.3 KiB
PHP
Raw Normal View History

2022-11-28 14:54:00 +00:00
<?php
namespace App\Http\Controllers\Admin;
2022-12-06 09:35:57 +00:00
use App\Exceptions\EmqxSupportException;
2022-11-28 14:54:00 +00:00
use App\Http\Controllers\Controller;
use App\Support\EmqxSupport;
2023-01-10 13:42:27 +00:00
use Illuminate\Http\RedirectResponse;
2022-11-28 14:54:00 +00:00
use Illuminate\Http\Request;
2023-01-10 13:42:27 +00:00
use Illuminate\View\View;
2022-11-28 14:54:00 +00:00
class DeviceController extends Controller
{
2023-01-10 13:42:27 +00:00
public function index(Request $request): RedirectResponse|View
2022-11-28 14:54:00 +00:00
{
$emqx = new EmqxSupport();
2022-12-06 09:35:57 +00:00
try {
$clients = $emqx->clients([
2023-01-10 13:42:27 +00:00
'clientid' => $request->input('client_id'),
'username' => $request->input('username'),
'page' => $request->input('page'),
2022-12-06 09:35:57 +00:00
]);
2023-01-10 13:42:27 +00:00
} catch (EmqxSupportException $e) {
2022-12-06 09:35:57 +00:00
return back()->with('error', $e->getMessage());
}
2022-11-28 14:54:00 +00:00
return view('admin.device.index', compact('clients'));
}
//
// public function show(Request $request, $client_id)
// {
// $emqx = new EmqxSupport();
//
// $client = $emqx->clients(['clientid' => $client_id]);
//
// return view('admin.device.show', compact('client'));
// }
2023-01-10 13:42:27 +00:00
/**
* @throws EmqxSupportException
*/
public function destroy($client_id): RedirectResponse
2022-11-28 14:54:00 +00:00
{
$emqx = new EmqxSupport();
$emqx->kickClient($client_id);
return back()->with('success', '此客户端已下线。');
}
}