multiple unique column

good evening, I have 3 tables users, jobs and finally the pivot table user_job with the pivot fields "start_date" and "end_date" and also $table->unique('user_id','job_id','start_date') , in my UserResource I have the following repeater: Repeater::make('userJobs') ->label('') ->relationship() ->schema([ Select::make('job_id') ->options(Job::all()->pluck('name', 'id')) ->required() ->unique('user_job',ignoreRecord: true), DatePicker::make('date_start') ->required() ->format('d/m/Y'), DatePicker::make('date_end') ->format('d/m/Y'), ]), If possible, I would like some help to respect $table->unique('user_id','job_id','start_date') thank you in advance for your help
3 Replies
karim charfaoui
karim charfaouiOP11mo ago
I do that that but doesn't work : ->unique('user_job',ignoreRecord: true,modifyRuleUsing: function (Unique $rule,callable $get) { return $rule ->where('date_start',$get('date_start')) ->where('job_id',$get('job_id')) ->where('user_id',$get('user_id')); })
bogus
bogus11mo ago
try this:
//...
->unique('user_job', 'job_id', null, 'id', function ($rule, Forms\Get $get) {
return $rule
->where('date_start',$get('date_start'))
->where('job_id',$get('job_id'))
->where('user_id',$get('user_id'));

}),
// ..
//...
->unique('user_job', 'job_id', null, 'id', function ($rule, Forms\Get $get) {
return $rule
->where('date_start',$get('date_start'))
->where('job_id',$get('job_id'))
->where('user_id',$get('user_id'));

}),
// ..
karim charfaoui
karim charfaouiOP11mo ago
@bogus same problem : integrity constraint violation: 1062 Duplicate entry any other suggestion please please some help
Want results from more Discord servers?
Add your server