Jaimin
Jaimin

Reputation: 872

two fields validation with laravel 5

I want to check uniqueness of a slug + category field.

I want to cross check both the fields with database..

both fields belongs in the same table..

category could be 1 or 2.

table name is pages..

my validation code is something like this

$catid = \Request::input('category');

$this->validate($request, [
        'title' => 'required',
        'category' => 'required',
        'slug' => "unique:pages|category,$catid",
        'body' => 'required',
    ]);

i can't figure out what m i doing wrong? any suggestions will be helpful..

Upvotes: 2

Views: 395

Answers (1)

igs013
igs013

Reputation: 1420

Try this:

'slug' => 'unique:pages,slug,NULL,id,category,' . $catid

Upvotes: 2

Related Questions