Skip to content

Latest commit

 

History

History
28 lines (25 loc) · 875 Bytes

nova-validation.md

File metadata and controls

28 lines (25 loc) · 875 Bytes

Nova | Validation

Resource | Validation | Combination of FK fields must be unique

// A machine has a type and a color, both key's to other tables. The combination must be unique in the machine table.

BelongsTo::make('Color')
    ->creationRules([
        Rule::unique('machine', 'color_id')
            ->where('color_id', $request->input('color'))
    ])
    ->updateRules([
        Rule::unique('machine', 'color_id')
            ->where('color_id', $request->input('color'))
            ->ignore($request->resourceId)
    ]),
BelongsTo::make('Type')
    ->creationRules([
        Rule::unique('machine', 'type_id')
            ->where('type_id', $request->input('type'))
    ])
    ->updateRules([
        Rule::unique('machine', 'type_id')
            ->where('type_id', $request->input('type'))
            ->ignore($request->resourceId)
    ]),