-2
I would like to know how it is possible to perform validation in the 6.x Standard for composite keys ?
I am wanting to insert new data a pivot table that has many link to many with two other tables.
public function up()
{
Schema::create('acl_cm_tecnicos', function (Blueprint $table) {
$table->unsignedInteger('id_tecnicos');
$table->unsignedInteger('id_cms');
$table->primary(['id_tecnicos', 'id_cms']);
$table->foreign('id_tecnicos')->references('id')->on('ctrl_lista_tecnicos');
$table->foreign('id_cms')->references('id')->on('ctrl_cm_tecnicos');
});
}
I performed tests for entering new data are ok !
But I would like to have a validation on backend
, to avoid error in the application in cases of trying to enter duplicate records.
I tried to create some validations like this.
public function store(Request $request)
{
//$cadAcl = $this->objAcl->create([
// 'id_tecnicos'=>$request->id_tecnico,
// 'id_cms'=>$request->id_cm,
//]);
$datatec = $this -> $request->tecnico_id;
$datacm = $this -> $request->id_cms;
$validacao = $this->validate($request, [
'id_tecnicos' => 'unique:acl_cm_tecnicos,id_tecnicos,NULL,id,id_cms'.$datacm,
'id_cms' => 'unique:acl_cm_tecnicos,id_cms,NULL,id,id_tecnicos'.$datatec,
]
);
dd($validacao);
But I confess that I am a little lost by the attempts I have already made. On this last attempt I have following error in output of dd($validation);
Errorexception Undefined Property: App Http Controllers Scheduling Resource Accfticscontroller::$POST /acltecnicos HTTP/1.1 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8,application/Signed-exchange;v=B3;q=0.9 Accept-Encoding: gzip, deflate, br Accept-Language: en-US,en;q=0.9,en-BR;q=0.8,en;q=0.7 Cache-Control: max-age=0 Connection: Keep-Alive Content-Length: 372 Content-Type: Multipart/form-date; Boundary=---Webkitformboundarydpbr1ikfb0ntx9du Cookie: XSRF-TOKEN=Nlnjm0zjk4njm1nzg0otq2nta1ytu0nta0zgrknza1zjfhmdu1mge1ntjmin0%3D; laravel_session=eyJpdiI6IjUrb3EzK3hBd3ZXSEtRTTFFVGswZUE9PSIsInZhbHVlIjoidjNSQ3pIM0ZOSytqMWlPZWEwS1N6VmlBZ2VRT21DRHlBNHRlOTk5cDRQaGtpTjN3bnZ5V2djeXBhb0F1WmJzVDliWncybXFOWnRqTkJcL1g2UHVMNVIyODk2aVlkdlBIdTdoQzJtbmFya3ZQd3pxQngxUTA4K3p4ZUhmMkNwR3dxIiwibWFjIjoiZDliNGJlNzQ5MmZhMWU1ODY3ZjcyYjk2ztg1nmeyzdgxogjjnmzjmwnhyzcxmzi2mzgynzdjyzgwy2uyztu4yij9 Dnt: 1 Host: 127.0.0.1:8000 Origin: http://127.0.0.1:8000 Referer: http://127.0.0.1:8000/tecnicos/980/Edit Sec-Fetch-Dest: Document Sec-Fetch-Mode: navigate Sec-Fetch-Site: same-origin Sec-Fetch-User: ?1 Upgrade-Insecure-Requests: 1 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) Applewebkit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36 Cookie: XSRF-TOKEN=Jpfbbalpgyx59xvgtdrsgcshyyfsbaqeuik8gjts; laravel_session=zY4ITpf8RvqzZ55HJMwlKOra8QuErGbPExGDel5S
Thank you very much it worked out vlw by force !!!
– Heliezer Garcia