我正在使用带有护照包的 Laravel 5 来管理用户的操作,一切都按预期进行,直到有一天没有API起作用,当我尝试发送请求注册API的请求时,没有任何反应,使用邮递员进行测试,我发现请求为array(0){}
!!!,请求为空,这是API路由
Route::group(['namespace' => 'User', 'prefix' => '/User'], function(){
Route::post('Login','UserAuthController@Login');
Route::post('ForgetPassword','UserAuthController@ForgetPassword');
Route::post('Register','UserAuthController@Register');
}
这是我用来注册的代码
public function Register(Request $request)
{
$validator = Validator::make(
$request->all(),
[
'title_id' => 'required',
'first_name' => 'required|min:3',
'last_name' => 'required|min:3',
'name' => 'required|min:3',
'UserName' => 'required|min:3',
'email' => 'required|email',
'password' => 'required',
'passwordConfirm' => 'required|same:password',
'dateofbirth' => 'required',
'Address' => 'required',
'region_id' => 'required',
'city_id' => 'required',
'country_id' => 'required',
'work_mobile' => 'required'
],
[
'required'=>'You cant leave :attribute field empty',
'passwordConfirm.same'=> ':attribute should match the password field ',
'min'=>'The :attribute has to be :min chars long',
]
);
if ($validator->fails()) {
return response()->json([
'Success' => false,
'Message' => $validator->messages(),
'Data' => null,
], $this->FailedStatus);
}
$user = User::where('email', $request->email)->first();
if ($user === null) {
$input = $request->all();
$input['password'] = bcrypt($input['password']);
$input['passwordConfirm'] = bcrypt($input['passwordConfirm']);
$input['is_active'] = 0;
$billing = [
'first_name' => $request->first_name,
'last_name' => $request->last_name,
'company' => '',
'address_1' => $request->Address,
'address_2' => '',
'city' => 'EF',
'state' => 'EF',
'postcode' => '',
'country' => 'EG',
'email' => $request->email,
'phone' => $request->work_mobile
];
$shipping = [
'first_name' => $request->first_name,
'last_name' => $request->last_name,
'company' => '',
'address_1' => $request->Address,
'address_2' => '',
'city' => 'EF',
'state' => 'EF',
'postcode' => '',
'country' => 'EG',
];
$data = [
'email' => $request->email,
'first_name' => $request->first_name,
'last_name' => $request->last_name,
'username' => $request->UserName,
'password' => $request->password,
'billing' => $billing,
'shipping' => $shipping
];
$Customer = app(wooClient::class)->wp_register_newcustomer($data);
if ( $Customer === null)
{
return response()->json([
'Success' => true,
'Message' => $Customer,
'Data' => $Customer,
'BaseURL' => null,
], 401);
}
$input['wpuserid'] = $Customer->id;
$InsertUser = User::create($input);
$success['token'] = $InsertUser->createToken('MyApp')->accessToken;
$success['userDetails'] = $InsertUser->load('Background')->load('ProfilePic');
$success['videos'] = $this->getLastVideoForUser();
return response()->json([
'Success' => true,
'Message' => $validator->messages(),
'Data' => $success,
'BaseURL' => null,
], 200);
}
return response()->json([
'Success' => false,
'Message' => $validator->messages(),
'Data' => null,
], $this->FailedStatus);
}
邮递员返回:
Request {#43
#json: null
#convertedFiles: null
#userResolver: Closure($guard = null) {#803
class: "Illuminate\Auth\AuthServiceProvider"
this: AuthServiceProvider {#23 …}
parameters: {
$guard: {
default: null
}
}
use: {
$app: Application {#2 …}
}
file: "/home/ahameed/SmartWave/Mobile/NagwaZahran/nz/vendor/laravel/framework/src/Illuminate/Auth/AuthServiceProvider.php"
line: "83 to 85"
}
#routeResolver: Closure() {#805
class: "Illuminate\Routing\Router"
this: Router {#26 …}
use: {
$route: Route {#420 …}
}
file: "/home/ahameed/SmartWave/Mobile/NagwaZahran/nz/vendor/laravel/framework/src/Illuminate/Routing/Router.php"
line: "650 to 652"
}
+attributes: ParameterBag {#45
#parameters: []
}
+request: ParameterBag {#44
#parameters: []
}
+query: ParameterBag {#51
#parameters: []
}
+server: ServerBag {#47
#parameters: array:26 [
"DOCUMENT_ROOT" => "/home/ahameed/SmartWave/Mobile/NagwaZahran/nz/public"
"REMOTE_ADDR" => "127.0.0.1"
"REMOTE_PORT" => "32852"
"SERVER_SOFTWARE" => "PHP 7.2.18 Development Server"
"SERVER_PROTOCOL" => "HTTP/1.1"
"SERVER_NAME" => "127.0.0.1"
"SERVER_PORT" => "8001"
"REQUEST_URI" => "/api/User/Register"
"REQUEST_METHOD" => "POST"
"SCRIPT_NAME" => "/index.php"
"SCRIPT_FILENAME" => "/home/ahameed/SmartWave/Mobile/NagwaZahran/nz/public/index.php"
"PATH_INFO" => "/api/User/Register"
"PHP_SELF" => "/index.php/api/User/Register"
"HTTP_CACHE_CONTROL" => "no-cache"
"HTTP_POSTMAN_TOKEN" => "99fc7dac-8fb7-4e26-b3d7-d86170405970"
"CONTENT_TYPE" => "text/plain"
"HTTP_CONTENT_TYPE" => "text/plain"
"HTTP_USER_AGENT" => "PostmanRuntime/7.6.1"
"HTTP_ACCEPT" => "*/*"
"HTTP_HOST" => "127.0.0.1:8001"
"HTTP_ACCEPT_ENCODING" => "gzip, deflate"
"CONTENT_LENGTH" => "23"
"HTTP_CONTENT_LENGTH" => "23"
"HTTP_CONNECTION" => "keep-alive"
"REQUEST_TIME_FLOAT" => 1559040214.0144
"REQUEST_TIME" => 1559040214
]
}
+files: FileBag {#48
#parameters: []
}
+cookies: ParameterBag {#46
#parameters: []
}
+headers: HeaderBag {#49
#headers: array:9 [
"cache-control" => array:1 [
0 => "no-cache"
]
"postman-token" => array:1 [
0 => "99fc7dac-8fb7-4e26-b3d7-d86170405970"
]
"content-type" => array:1 [
0 => "text/plain"
]
"user-agent" => array:1 [
0 => "PostmanRuntime/7.6.1"
]
"accept" => array:1 [
0 => "*/*"
]
"host" => array:1 [
0 => "127.0.0.1:8001"
]
"accept-encoding" => array:1 [
0 => "gzip, deflate"
]
"content-length" => array:1 [
0 => "23"
]
"connection" => array:1 [
0 => "keep-alive"
]
]
#cacheControl: array:1 [
"no-cache" => true
]
}
#content: null
#languages: null
#charsets: null
#encodings: null
#acceptableContentTypes: null
#pathInfo: "/api/User/Register"
#requestUri: "/api/User/Register"
#baseUrl: ""
#basePath: null
#method: "POST"
#format: null
#session: null
#locale: null
#defaultLocale: "en"
-isHostValid: true
-isForwardedValid: true
basePath: ""
format: "html"
}