Ad

Validate That Tags Exist

- 1 answer

I have a form with tags which send as array

<select class="tags form-control"  name="tags[]" multiple="multiple">
</select>

I have suitable relationship and everything works. But I try to valdiate any checked tag. I want to validate that this tags exist. My rules lool like this

public function rules()
{
    return [

        'tags.id' => 'required|integer|exists:tags.id'

    ];
}

But it display error message "The tags.id field is required" . How I can solve my problem?

Ad

Answer

You don't have id. Try following :

public function rules()
{
    return [

        'tags.*' => 'required|integer|exists:tags.id'

    ];
}
Ad
source: stackoverflow.com
Ad