我在React中也是Lumen的新手,所以我不知道我的代码出了什么问题,它返回如下错误,我正在使用axios库。 在邮递员中很好用
这是我的反应代码
handleFormSubmit = (event) => {
event.preventDefault();
const data = {
name: this.state.name,
email: this.state.email,
password: this.state.password
}
// Axios.post('http://localhost:8000/api/register', data).then(res => {
// console.log(res);
// })
fetch('http://localhost:8000/api/register', {
method: 'POST',
body: data
}).then(res => {
console.log(res);
});
}
流明代码
public function register(Request $request)
{
$rules = [
'email' => 'required|email|unique:users',
'name' => 'required|min:5',
'password' => 'required|min:6'
];
$this->validate($request, $rules);
$name = $request->input('name');
$email = $request->input('email');
$password = $request->input('password');
$hashPassword = Hash::make($password);
$user = User::create([
'email' => $email,
'name' => $name,
'password' => $hashPassword
]);
return response()->json(['status' => 'success', 'user_id' => $user->id], 201);
}
任何解决方案表示赞赏!