add parent path

main
nocode 1 year ago
parent 0f7ad64588
commit 687ef5b28e
  1. 14
      app/Http/Controllers/Api/AuthApiController.php
  2. 2
      app/Models/Agent.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 = '';

@ -13,7 +13,7 @@ class Agent extends Model
protected $fillable = [
'id',
'name',
'root_path',
'parent_path',
'grant',
'type',
'phone',

Loading…
Cancel
Save