Skip to content

Implement list_exists validation rule #77

Closed
@DenTray

Description

@DenTray

To optimise the validation of list of values through the DB table, we need to implement custom validation rule.

How it should works:

public function rules(): array
{
    return [
        //will make `whereIn` query to determine which of values are not exists in DB
        'ids' => 'array|list_exists:users,id',
        'ids.*' => 'integer',

        //will works the same as in previous example but will find record in the `clients` table in `user_id` field and pluck `id` field from the input collection
        'users' => 'array|list_exists:clients,user_id,id',  
        'users.id' => 'integer'
    ];
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions