我有两个名为area_managers
和shopkeepers
的表。我想从area_managers
中validate email
,同时以一种与shopkeepers
和area_managers
表的电子邮件不匹配的方式进行更新。我尝试了以下方式,但它甚至不允许相应用户的现有电子邮件。
public function update(Request $request, AreaManager $areaManager)
{
$request->validate([
'email'=>'required|email|unique:shopkeepers,email|unique:area_managers,email,'.$areaManager->id,
]);
$areaManager-> email = $request->email;
$areaManager->update();
return redirect()->route('area_manager.edit',$areaManager->id);
}
快速检查可以是这样的:
$checkAreaManagers = DB::table('area_managers')->where('email', '=', $request->email)->first();
$checkShopkeepers = DB::table('shopkeepers')->where('email', '=', $request->email)->first();
if ($checkAreaManagers === null || $checkShopkeepers === null) {
// Proceed with the update
$areaManager->email = $request->email;
$areaManager->save();
}
if ($checkAreaManagers !== null || $checkShopkeepers !== null) {
// Cancel the update (Your logic here)
dd('Duplicate found');
}
您应该使用以下命令扮演一个角色:
php手工制作:规则角色名称
然后在passs方法中设置查询,然后在验证器中使用