0

So I have 2 plugins, say for example Categories and Sub Categories.

In Categories plugin I have 2 records Category 1 and Category 2.

In sub categories I have 2 fields .. 'Select Parent category' which will have a dropdown of Categories plugin, having dropdown values as Category 1 and Category 2 and another field as name in which I can add name of my sub category.

Now I have set a unique validation for my name field something like this

public $rules = [
        'name' => 'required|unique:technobrave_supportcategories_,name',
    ];

This is working fine for me, however, I want unique validation based on my category_id as well .. IS this possible ?

I am trying this https://stackoverflow.com/a/50350625/6829420 but its not working for me.

Is this possible in OctoberCMS while adding/updating ? Please suggest me

Thanks

Mittul At TechnoBrave
  • 1,142
  • 3
  • 25
  • 70

1 Answers1

0

@Mittul What does your ID's looke like? I typically have a record id that always auto increments and then will add a unique ID (UID) if need be that is usually manually entered.

Why couldn't this work? Unless I am not fully understanding how you want your relationship to work.

public $rules = [
        'id' => 'required|unique:technobrave_supportcategories_,category_id',
        'name' => 'required|unique:technobrave_supportcategories_,name'
    ];
Pettis Brandon
  • 875
  • 1
  • 6
  • 8