Ich habe ein Feld namens mac, wo ich Mac-Adresse speichern, aber ich brauche es einzigartig zu vermeiden, doppelte MAC-Adresse zu vermeiden.Laravel eindeutiges Feld validieren nicht funktioniert
Code:
return [
'user_id' => 'required|integer',
'mac' => array('required|unique:mac', 'regex:/^([0-9A-Z]{2}[-]){5}([0-9A-Z]{1,2})$/'),
];
Fehler: Methode [validateRequired | einzigartig] existiert nicht.
Struktur:
CREATE TABLE `devices` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`user_id` int(10) unsigned NOT NULL,
`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`mac` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`content` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`status` tinyint(1) NOT NULL DEFAULT '0',
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
`deleted_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `devices_mac_unique` (`mac`),
KEY `devices_user_id_foreign` (`user_id`),
CONSTRAINT `devices_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
es sollte 'sein 'mac' => '[erforderlich, einzigartig: mac ...]'' – linuxartisan
Das Feld unter Validierung muss auf einer bestimmten Datenbanktabelle eindeutig sein. –
Fügen Sie Ihre Tabellenstruktur hier –