ignoreRecord for TextColumn with different slugs for each domain

Hello! I'm fighting for hours with this and maybe just your experience can help me in minutes. The situation Users should be able to create custom links for different domains. Model 1 = Domain Model 2 = Link (with column for the 'slug') Different domains should be able to have same slug: domain1/slugxyz domain2/slugxyz So I created a custom Rule at that input on the Form.
->rules([
fn (Get $get): Closure => function(string $attribute, mixed $value, Closure $fail) use ($get): bool {
$slugInDomain = Link::where('domain_id', $get('domain_id'))
->where('slug', '=', $value)
->first();

if ( $slugInDomain ) {
$fail("The slug is already in use.");
}

return true;
}
])
->rules([
fn (Get $get): Closure => function(string $attribute, mixed $value, Closure $fail) use ($get): bool {
$slugInDomain = Link::where('domain_id', $get('domain_id'))
->where('slug', '=', $value)
->first();

if ( $slugInDomain ) {
$fail("The slug is already in use.");
}

return true;
}
])
It gets the domain_id from the Select field with the ->live() option. The goal check if a Link for that Domain with that slug exists. If not, continue. If yes, give error The problem: when trying to edit a record, it says it already exists I tried the option ->unique(ignoreRecord: true). But, as i should be able to have same slug for different domains (but just 1 for each domain), i didn't manage to make it work. Thank you!
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server