4 回答

TA貢獻(xiàn)1848條經(jīng)驗(yàn) 獲得超2個(gè)贊
做這樣的事情:
根據(jù)插入請(qǐng)求使用
'domain' => [
...
'unique:websites,domain'
]
根據(jù)更新請(qǐng)求使用
'domain' => [
...
"unique:websites,domain,{$this->website->id}"
]
要么
'domain' => [
...
Rule::unique('websites', 'domain')->ignore($this->website)
]

TA貢獻(xiàn)1775條經(jīng)驗(yàn) 獲得超8個(gè)贊
您不需要在 ignore Rule 中傳遞重復(fù)的列來(lái)指示驗(yàn)證器忽略網(wǎng)站域,除了它自己?jiǎn)??例如?/p>
Rule::unique('apps')->ignore($website->id)

TA貢獻(xiàn)2016條經(jīng)驗(yàn) 獲得超9個(gè)贊
您將 $request->all() 作為驗(yàn)證消息傳遞。請(qǐng)?jiān)囋嚕?/p>
$website = $websiteModel->find($id);
$request->validate([
'subDomainName' => ['required','regex:/^[A-Za-z0-9 ]+$/'],
'subDomainSuffix' => ['required'],
'packageType' => ['required'],
'themeid' => ['required'],
'lang' => ['required'],
'user' => ['required'],
'domain' => [
'required',
'string',
'min:2',
'max:255',
Rule::unique('apps')->ignore($website)
],
]);

TA貢獻(xiàn)1900條經(jīng)驗(yàn) 獲得超5個(gè)贊
請(qǐng)?jiān)囋囘@個(gè) 。它有助于解決你的問(wèn)題
在文件頂部使用異常和驗(yàn)證器
use Exception;
use Validator;
$rules = [
'subDomainName' => 'required|unique:sub_domain_name',
];
$validator = Validator::make($request->all(), $rules, $message);
if ($validator->fails()) {
throw new Exception(implode('\n', $validator->errors()->all()));
}
sub_domain_name :這是數(shù)據(jù)庫(kù)列名
- 4 回答
- 0 關(guān)注
- 155 瀏覽
添加回答
舉報(bào)