我只需要一个 API 来验证电子邮件的唯一性,而无需创建模型或资源中间人,这是我的镜头
客户.vue
fetch(`api/validateEmail/${email}`)
.then(res => res.json)
.then(res => this.isEmailDuplicated = res.data)
.catch(e => console.log(e))
接口.php
Route::get('validateEmail/{email}', function ($email) {
return response(appCustomer::where('email', $email)->exists());
}
提前谢谢你。
这样它应该正常工作,因为它返回的是有效的响应,而不是简单的布尔值。
Route::get('validateEmail/{email}', function ($email) {
$exists = appCustomer::where('email', $email)->exists();
return response()->json([
'exists' => $exists
]);
}