Closed carlospinhod closed 1 year ago
This should help - link to SO.
Basically 'unique:user_table,username,NULL,id,clud_id,' . $form->model()->club_id
or something similar.
Or use more verbose OOP-based approach as described in this section of Laravel docs (last example).
'username' => [Rule::unique('user_table')->where(fn (Builder $query) => $query->where('club_id', $club_id))]
@alexoleynik0 thank you for your hints, i have solved my problem using something like this
$form->number('id','ID')->rules(['required' => Rule::unique('user_table')->where(fn(Builder $query) => $query->where('id', '!=', $form->model()->id)->where('club_id', $club_id))])->required();
Description:
Hi, i need to validate if a value is unique but i have to filter the "unique search" with other field for example: if the username is unique for this club_id. hope you can help me! ps: the ideia is to validate before submiting, and the club id is a variable i get from php
Steps To Reproduce:
table example: (user_id, username, club_id)
$form->text('username')->updateRules(['required', "unique:user_table,username,{{id}}"]);