Arrays 如何在邮递员中分解尸体请求-使用laravel

Arrays 如何在邮递员中分解尸体请求-使用laravel,arrays,json,laravel,Arrays,Json,Laravel,我正在尝试将我的body请求从postman的1个对象分解为多个对象当前我的Json如下所示: { "email": "shahzad@ovadamd.com", "password": "admin123", "password_confirmation": "admin123", "status": 0, "first_name": "Shahzad", "middle_name": "Hussain", "last_name": "Shah", "date_of_birth":

我正在尝试将我的body请求从postman的1个对象分解为多个对象当前我的Json如下所示:

      {
"email": "shahzad@ovadamd.com",
"password": "admin123",
"password_confirmation": "admin123",
"status": 0,
"first_name": "Shahzad",
"middle_name": "Hussain",
"last_name": "Shah",
"date_of_birth": "2015-01-01",
"gender": "M",
"area_id": 1,
"address": "Minhatten NY",
"city": "New York",
"state": "Washington",
"zip": "12312",
"fax": "111-111-1111",
"phone_extension": "2471",
"work_phone": "111-111-1111",
"phone_no": "111-111-1111",
"emergency_contact": "111-111-1111",
"social_security": "111-11-1111",
"module_id": 1,
"role_id": 1,
"speciality_id": 1,
"facility_id": 1,
"priv_title": "can edit doctor",
"priv_key": "ced",
"display_group": "Doctor",
"prev_id" :1
   }
我想进一步拆分这个json,如下所示

      {
"user_profile": {
    "email": "shahzadg@ovadamd.com",
    "password": "admin123",
    "password_confirmation": "admin123",
    "status": 0,
    "first_name": "Shahzad",
    "middle_name": "Hussain",
    "last_name": "Shah",
    "date_of_birth": "2015-01-01",
    "gender": "M",
    "area_id": 1,
    "address": "Minhatten NY",
    "city": "New York",
    "state": "Washington",
    "zip": "12312",
    "fax": "111-111-1111",
    "phone_extension": "2471",
    "work_phone": "111-111-1111",
    "phone_no": "111-111-1111",
    "emergency_contact": "111-111-1111",
    "social_security": "111-11-1111",
    "module_id": 2,
    "role_id": 1
    },

"prev":{

    "speciality_id": 1,
    "facility_id": 1,
    "priv_title": "can edit doctor",
    "priv_key": "ced",
    "display_group": "Doctor",
    "prev_id" :1
}
     }
在我的控制器中,我创建了一个user_profile和prev变量,然后我正在合并:

public function register(Request $request) {


    $body = $request->all();

    $userProfile = $body['user_profile'];
    $userPrev = $body['prev'];

    $bodyObj = array_merge($userProfile, $userPrev);
    $bodyObj['token'] = $body['token'];

    $validator = UserValidations::validateUser($bodyObj);

    if ($validator->fails()) {
        return response([
            'status' => false,
            'message'   => __('messages.validation_errors'),
            'errors' => $validator->errors()->all()
        ], 200);
    }
但是它说不能添加或更新子行,但是当我删除array\u merge并将json对象删除为简单对象时,这个错误没有任何关系。它工作正常,我不知道问题出在哪里,我陷入了这个问题

这里需要你的帮助

                 array:3 [
          "user_profile" => array:22 [
         "email" => "shahzadshahg@hotmail.com"
        "password" => "admin123"
"password_confirmation" => "admin123"
"status" => 0
"first_name" => "Shahzad"
"middle_name" => "Hussain"
"last_name" => "Shah"
"date_of_birth" => "2015-01-01"
"gender" => "M"
"area_id" => 1
"address" => "Minhatten NY"
"city" => "New York"
"state" => "Washington"
"zip" => "12312"
"fax" => "111-111-1111"
"phone_extension" => "2471"
"work_phone" => "111-111-1111"
"phone_no" => "111-111-1111"
"emergency_contact" => "111-111-1111"
"social_security" => "111-11-1111"
"module_id" => 2
"role_id" => 2
    ]
   "prev" => array:6 [
"speciality_id" => 1
"facility_id" => 1
"priv_title" => "can edit doctor"
"priv_key" => "ced"
"display_group" => "Doctor"
"prev_id" => 1
  ]
   "token" => "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9sb2NhbGhvc3RcL2ZlYXR1cmUtbWFzdGVyXC9hcGlcL2ZkX2xvZ2luIiwiaWF0IjoxNTU0MDMzNTI4LCJleHAiOjE1ODU1Njk1MjgsIm5iZiI6MTU1NDAzMzUyOCwianRpIjoiaXQyZm1KdmpmeWNOMXJwbyIsInN1YiI6MiwicHJ2IjoiNGFjMDVjMGY4YWMwOGYzNjRjYjRkMDNmYjhlMWY2MzFmZWMzMjJlOCIsImFjY2Vzc19tb2R1bGUiOiJmcm9udC1kZXNrIiwibW9kdWxlX2lkIjoyLCJ1c2VyX2lkIjoyfQ.nJXJapamtghGZZ_LZZlZLTE64Bs_ckQoWKanXNMD4Nc"
]

array\u merge
函数工作正常


评论不适用于扩展讨论或调试会话。如果您想澄清您的问题或答案,请编辑。如果您有后续问题,请提出新问题。
public function register(Request $request) {


    $body = $request->all();

    $userProfile = $body['user_profile'];
    $userPrev = $body['prev'];

    $bodyObj = array_merge($userProfile, $userPrev);
    $bodyObj['token'] = $body['token'];




    return response()->json($bodyObj);


    DB::beginTransaction();

    try{

        $token = JWTAuth::getToken();
        $apy = JWTAuth::getPayload($token)->toArray();
        $request->merge(['module_id' => $apy['module_id']]);
        $request->request->add(['created_by' => Auth::user()->id]);
        $request->merge(['password' =>  bcrypt($request->input('password'))]);
        $user = $this->user->create($request->only($this->user->getModel()->fillable));
        $request->request->add(['user_id' => $user->id]);
        $this->userBasicInfo->create($request->only($this->userBasicInfo->getModel()->fillable));
        $this->userContactDetails->create($request->only($this->userContactDetails->getModel()->fillable));
        $this->userAccessModule->create($request->only($this->userAccessModule->getModel()->fillable));
        $this->userRoles->create($request->only($this->userRoles->getModel()->fillable));
        $this->verifyUser->create(['user_id' => $user->id, 'token' => str_random(40)]);

        Mail::to($user->email)->send(new VerifyMail($user));

        DB::commit();

        return response([
            'status' => true,
            'message' => 'User registered successfully',
        ], 200);

    } catch(\Exception $ex) {
        DB::rollback();
        return response([
            'status' => false,
            'message' => __('messages.validation_errors'),
            'errors' => $ex->getMessage(),
        ], 500);
    }
}
public function register(Request $request) {
    $body = $request->all();
    $userProfile = $body['user_profile'];
    $userPrev = $body['prev'];
    $bodyObj = array_merge($userProfile, $userPrev);
    $bodyObj['token'] = $body['token'];
    return response()->json($bodyObj);
    // $validator = UserValidations::validateUser($bodyObj);
    // if ($validator->fails()) {
    //     return response([
    //         'status' => false,
    //         'message'   => __('messages.validation_errors'),
    //         'errors' => $validator->errors()->all()
    //     ], 200);
    // }
}