自定义验证不适用于Laravel中的更新
在我的Laravel-5.8项目中,我有以下自定义验证:自定义验证不适用于Laravel中的更新,laravel,validationrules,Laravel,Validationrules,在我的Laravel-5.8项目中,我有以下自定义验证: namespace App\Rules; use App\Models\Rating; use Illuminate\Contracts\Validation\Rule; class AllowedGrade implements Rule { public function __construct() { // } public function passes($attribute,
namespace App\Rules;
use App\Models\Rating;
use Illuminate\Contracts\Validation\Rule;
class AllowedGrade implements Rule
{
public function __construct()
{
//
}
public function passes($attribute, $value)
{
return Rating::where('mark_from', '<=', $value)
->where('mark_to', '>=', $value)
->doesntExist();
}
public function message()
{
return 'The :attribute as score range is used.';
}
}
我将其用于路由url:->ignore($this->rating)
它在create中运行良好,但当我尝试更新时,收到了验证消息:
The Min. Score as score range is used.
The Max. Score as score range is used.
引述如下:
返回“使用分数范围时的:属性”
如何使其也适用于更新
谢谢您正在将
忽略
与唯一
规则一起使用,而不是您的自定义规则,验证失败消息来自您的自定义规则
The Min. Score as score range is used.
The Max. Score as score range is used.