作者 zhl

u

... ... @@ -5,6 +5,7 @@ namespace App\Http\Middleware\Bside;
use App\Enums\Common\Code;
use App\Models\ProjectMenu;
use App\Models\ProjectRole as ProjectRoleModel;
use App\Services\ProjectServer;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
... ... @@ -29,6 +30,9 @@ class LoginAuthMiddleware
if(empty($info)){
return response(['code'=>Code::USER_ERROR,'msg'=>'当前用户未登录']);
}
// 设置数据信息
ProjectServer::useProject($info['project_id']);
//操作权限设置
$projectRoleModel = new ProjectRoleModel();
$role_info = $projectRoleModel->read(['id'=>$info['role_id']]);
... ...
<?php
/**
* Created by PhpStorm.
* User: zhl
* Date: 2023/4/17
* Time: 15:16
*/
namespace App\Services;
use App\Models\Project;
/**
* Class ProjectServer
* @package App\Services
*/
class ProjectServer extends BaseService
{
/**
* @param $project_id
* @return bool
*/
public static function useProject($project_id)
{
$project = Project::getProjectById($project_id);
if (empty($project))
return false;
// 设置 database.connections.custom_mysql 配置
config(['database.connections.custom_mysql.host' => $project->mysqlConfig()->host]);
config(['database.connections.custom_mysql.port' => $project->mysqlConfig()->port]);
config(['database.connections.custom_mysql.database' => $project->databaseName()]);
config(['database.connections.custom_mysql.username' => $project->mysqlConfig()->user]);
config(['database.connections.custom_mysql.password' => $project->mysqlConfig()->password]);
// 设置 redis 配置
return true;
}
}
\ No newline at end of file
... ...