I'm trying to implement Register User
in NuxtJS. However, I'm having this issue like below
vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php
Route::post('register', 'V1\Auth\LoginController@register');
I'm try change it to get method
and access it by 127.0.0.1:8000/api/register
its work pretty fine.
i still have no idea, why i got this POST http://127.0.0.1:3000/api/register 404 (Not Found)
async registerUser() {
try {
await this.$axios.post(`api/register`, this.auth);
await this.$auth.login({
data: {
email: this.auth.email,
password: this.auth.password,
}
})
.then(res => {
console.log(res);
this.loading = false
// this.$router.push(`/auth/login`);
})
.catch(err => {
this.loading = false
this.$refs.form.validate(err.response.data.errors)
console.log(err.response);
})
} catch(e) {
// statements
console.log(e);
}
public function register(Request $request)
{
$request->validate([
'name' => 'required',
'email' => 'required|email',
'password' => 'required|between:6, 25',
]);
$user = new User();
$user->name = $request->name;
$user->email = $request->email;
$user->password = bcrypt($request->password);
$user->save();
return response()->json(['registered' => true ]);
}
I'll appreciate of all your Help.
Thanks.
您在 axios 中使用 3000 端口http://127.0.0.1:3000/api/register
,但 Laravel 使用 8000 http://127.0.0.1:8000/api/register
You have to establish the API base URL In NuxtJS APP.
The reason is that Your NuxtJS app set default it's own base URL But you have to configure backend URL for laravel API.
Example,
Try This
await this.$axios.post(`http://127.0.0.1:8000/api/register`, this.auth);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.