英文:
unique date validation in update function for a specific meter in laravel 9
问题
这是我的存储函数
public function store(Request $request)
{
$validatedData = $request->validate( [
'meter' => 'required',
'date' => 'required|date_format:Y-m-d|unique:meterreading,date,NULL,meter,'.$request->get('meter'),
]);
}
日期对于特定的表计是唯一的。它正常工作。
如何在更新函数中验证此内容:
public function update(Request $request, MeterReading $meterreading)
{
$updateData = $request->validate( [
'date' => 'required|date|unique:meterreading,date,'.$meterreading->id.',meter,'.$request->get('meter'),
]);
}
在更新表单时,错误消息会出现为“日期已被占用”。如何清除此消息。感谢您!
英文:
This is my store function
public function store(Request $request)
{
$validatedData = $request->validate( [
'meter' => 'required',
'date' => 'required|date_format:Y-m-d||unique:meterreading,date,NULL,meter,meter,'.$request->get('meter'),
]);
}
date is unique for a specific meter. Its working perfectly.
And how can i validate this in update function
public function update(Request $request, MeterReading $meterreading)
{
$updateData = $request->validate( [
'date' => 'required|date|unique:meterreading,date,'.$meterreading->id.',meter,meter,'.$request->get('meter'),
]);
While updating the form the error message comes as
The date has already been taken. How can i clear this.
TIA
答案1
得分: 0
public function update(Request $request, MeterReading $meterreading)
{
$updateData = $request->validate([
'date' => 'required|date|unique:meterreading,date,'.$meterreading->id.',id,meter,'.$meterreading->meter,
]);
}
英文:
public function update(Request $request, MeterReading $meterreading)
{
$updateData = $request->validate([
'date' => 'required|date|unique:meterreading,date,'.$meterreading->id.',id,meter,'.$meterreading->meter,
]);
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论