diff --git a/app/Http/Controllers/Api/AuthApiController.php b/app/Http/Controllers/Api/AuthApiController.php index 7b83319..9a0cc7e 100755 --- a/app/Http/Controllers/Api/AuthApiController.php +++ b/app/Http/Controllers/Api/AuthApiController.php @@ -112,14 +112,16 @@ class AuthApiController extends BaseAuthApiController $dataInsert = $this->transformRegisterData($request->all()); - + if (!empty($dataInsert)) { if (!empty($checkUserAgent->agent_id)) { $agentParent = Agent::find($checkUserAgent->agent_id); $grantParent = $agentParent->grant; + $parentPath = $agentParent->parent_path??null; } - + $userId = \App\Models\User::insertGetId($dataInsert); + if ($userId) { $dataAgentInsert = [ 'name' => $dataInsert['name'] ?? '', @@ -130,7 +132,12 @@ class AuthApiController extends BaseAuthApiController 'address' => $dataInsert['address'] ?? '', ]; $agentInsertId = Agent::insertGetId($dataAgentInsert); + if ($agentInsertId) { + if(!empty($parentPath)){ + $myParentPath = $this->addParentPath($parentPath, $agentInsertId); + Agent::where('id', $agentInsertId)->update(['parent_path' => $myParentPath]); + } AgentUser::insert([ 'user_id' => $userId, 'agent_id' => $agentInsertId, @@ -146,6 +153,9 @@ class AuthApiController extends BaseAuthApiController return response()->json(['status' => false, 'msg' => $this->getMessageReponse(2)]); } + public function addParentPath($parentPath, $userIdAdd){ + return rtrim($parentPath, '-') . '-' . $userIdAdd . '-'; + } public function generateNewCode($code) { $newCode = ''; diff --git a/app/Models/Agent.php b/app/Models/Agent.php index c18ee57..13eb19d 100755 --- a/app/Models/Agent.php +++ b/app/Models/Agent.php @@ -13,7 +13,7 @@ class Agent extends Model protected $fillable = [ 'id', 'name', - 'root_path', + 'parent_path', 'grant', 'type', 'phone',