43 lines
1.2 KiB
PHP
43 lines
1.2 KiB
PHP
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | YwxApp [ WE CAN DO IT JUST THINK ]
|
|
// +----------------------------------------------------------------------
|
|
// | Copyright (c) 2026-2036 http://ywxapp.cn All rights reserved.
|
|
// +----------------------------------------------------------------------
|
|
// | Author: ywxapp<admin@ywxapp.cn>
|
|
// +----------------------------------------------------------------------
|
|
declare(strict_types=1);
|
|
namespace app\api\controller\v1;
|
|
use ywxapp\controller\ApiController;
|
|
|
|
use think\Response;
|
|
|
|
/**
|
|
* Example 类
|
|
*
|
|
* @author ywxapp <admin@ywxapp.cn>
|
|
*/
|
|
class Example extends ApiController
|
|
{
|
|
|
|
public function index(): Response
|
|
{
|
|
$user = \ywxapp\model\BackendAdmin::where('id', 1)->findOrEmpty();
|
|
if (!$user->isEmpty()) {
|
|
# code...
|
|
|
|
$roles = $user->roles;
|
|
foreach ($roles as $role) {
|
|
//echo $role->name;
|
|
// 获取中间表模型
|
|
// dump($role->pivot);
|
|
}
|
|
}
|
|
return json([
|
|
'message' => 'This is version 1 of the API',
|
|
'data' => $user,
|
|
'role' => $user->roles
|
|
]);
|
|
}
|
|
}
|