我正在从天真地向laravel后端发送数据和图像,我可以在error_log($ request)中看到该数组;我还可以保存数据字符串

时间:2018-08-10 08:04:35

标签: json laravel react-native

下面是对本机代码的反应

register =()=> {         fetch('http://192.168.43.71/MobileRegistration',{         方法:“ POST”,         标头:{         'Accept':'application / json',         'Content-Type':'application / json',         },         正文:JSON.stringify({         “名称”:this.state.userName,         “电子邮件”:this.state.email,         “电话”:this.state.phoneNumber,         “地址”:this.state.Address,         “性别”:this.state.selected1,         “ StateOfOrigin”:this.state.selected2,         “ StateOfResidence”:this.state.selected3,         “密码”:this.state.password,         ProfilePic:this.state.photos

    }),
    })
    .then((response) => response.json())
    .then((responseJson) => {


    if(responseJson == "ok"){
             // redirect to profile page
             alert("Successfully registered");
             console.log(responseJson);
             this.props.navigation.navigate("Login", { userEmail: this.state.userEmail});
         }
         else if(responseJson == "Invalid Username or Password Please Try Again"){
             // redirect to profile page
        alert("not Successfully");

            console.log(this.state.photos);
            console.log(this.state.photos[1].uri);

         }
         else{
             alert("Wrong Login Detail");
             console.log(responseJson);
         }


    })
    .done();

    };

和laravel代码

 public function MobileRegistration(Request $request)

{

if($ request-> get('ProfilePic')){

error_log($ request); //是的,我在控制台中找到了数组,但似乎可以移动图像上传/图像

    $path = 'upload/images';
    $files = $request->ProfilePic;

    foreach ($files as $file)
        {
             $file_name = $file->getClientOriginalName(); //Get file original name
             $file->move($path , $file_name);
             $images[]=$file_name;               
        }

    $user = new User();
    $user->name =  $request->get('name');
    $user->email =  $request->get('email');
    $user->phone =  $request->get('phone');
    $user->Address =  $request->get('address');
    $user->gender =  $request->get('gender');
    $user->state_of_origin =  $request->get('StateOfOrigin');
    $user->state_of_resident =  $request->get('StateOfResidence');
    $user->profile_pic = json_encode($images);
    $user->password =  $request->get('password');
    $user->save();

    $n = $request->get('email');
    error_log($request);
    error_log($n);

 return Response::json($n);
 } else
     {

     $n ='Invalid Username or Password Please Try Again';
     return Response::json($n);
     }

}

和日志

enter image description here

0 个答案:

没有答案