Validate that tags exist

Fam*_*943 1 php validation laravel

I have a form with tags which send as array

<select class="tags form-control"  name="tags[]" multiple="multiple">
</select>
Run Code Online (Sandbox Code Playgroud)

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'

    ];
}
Run Code Online (Sandbox Code Playgroud)

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

小智 5

你没有id。尝试以下:

public function rules()
{
    return [

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

    ];
}
Run Code Online (Sandbox Code Playgroud)