增加 applications 功能

This commit is contained in:
iVampireSP.com 2023-01-21 03:26:23 +08:00
parent 401a13d3dc
commit 58f7a4a7ad
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132
3 changed files with 45 additions and 12 deletions

View File

@ -8,23 +8,16 @@
class ModuleController extends Controller
{
//
public function index()
{
$modules = (new Module)->all()->makeVisible('api_token');
// public function index() {
// $modules = Module::all();
//
// return $this->success($modules);
// }
return $this->success($modules);
}
public function show(Module $module): JsonResponse
{
return $this->success($module);
// $module = Module::find(request()->route('module'));
//
// return $this->success($module);
}
}

View File

@ -0,0 +1,33 @@
<?php
namespace App\Http\Controllers\Application;
use App\Http\Controllers\Controller;
use App\Models\PersonalAccessToken;
use App\Models\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Arr;
class UserController extends Controller
{
public function index()
{
$users = (new User)->paginate(10);
return $this->success($users);
}
public function show(User $user): JsonResponse
{
return $this->success($user);
}
public function auth($token): JsonResponse
{
$token = PersonalAccessToken::findToken($token);
return $token ? $this->success($token->tokenable) : $this->notFound();
}
}

View File

@ -2,6 +2,8 @@
use App\Http\Controllers\Application\ModuleController;
use App\Http\Controllers\Application\MqttAuthController;
use App\Http\Controllers\Application\UserController;
use Illuminate\Support\Facades\Route;
// MQTT Auth
@ -15,3 +17,8 @@
// Modules
Route::get('modules', [ModuleController::class, 'index'])->name('modules.index');
Route::get('modules/{module}', [ModuleController::class, 'show'])->name('modules.show');
Route::resource('users', UserController::class)->only(['index', 'show']);
Route::get('token/{token}', [UserController::class, 'auth']);