Turn of $rules for Seeder


I’ve setup several Validation Rules via $rules in the Model class which works well so far. I use an own relation for categories and tags and require those fields, if the type has a certain value:

'categories' => 'required_if:type,4,5,6,10,11,12|required_if:include_categories,1,2',
'tags' => 'required_if:type,1,2,3,7,8,9,13',

However, if I use the seeder with the Model::create() method, it doesnt work since the relations are created seperatly with ModelRelation::create['model_id => X, ‘category_id’ => Y];

Is there any way to solve this problem?

Yes, you can solve this using different seed code

$model->relation = [1,2,3];

I can’t see your seed code so it’s difficult to give a more specific suggestion.

1 Like
$csvFile = fopen(__DIR__ . "/../data/{$dataFolder}/valrules.csv", "r");
        while (($data = fgetcsv($csvFile, null, ",")) !== FALSE) {
            # ValRule
            $valRule = new ValidationRule();
                "type" => (int) $data['0'],
                "active" => (int) $data['1'],
                'trigger_title' => $data['2'],
                'trigger_tag_id'   => (int) $data['3'],
                'include_categories' => (int) $data['6'],
            # Tag IDs
            if (!empty($data['4']))
                $valRule->tags = explode(',', $data['4']);
            # Category IDs
            if (!empty($data['5'])) {
                $valRule->categories = explode(',', $data[5]);

Yep… could fix it this way. Thanks ^^