close

Laravel unique validation on multiple columns

Hello Guys, How are you all? Hope You all Are Fine. Today we are talking about Laravel unique validation on multiple columns in php. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Laravel unique validation on multiple columns Error Occurs?

Today we are talking about Laravel unique validation on multiple columns in php.

How To Solve Laravel unique validation on multiple columns Error ?

  1. How To Solve Laravel unique validation on multiple columns Error ?

    To Solve Laravel unique validation on multiple columns Error
    Try this rule:
    'data.ip' => 'required|unique:servers,ip,'.$this>id.'|unique:servers,hostname,'.$this->id

  2. Laravel unique validation on multiple columns

    To Solve Laravel unique validation on multiple columns Error
    Try this rule:
    'data.ip' => 'required|unique:servers,ip,'.$this>id.'|unique:servers,hostname,'.$this->id

Solution 1

This works for me for both create and update.

[
     'column_1' => 'required|unique:TableName,column_1,' . $this->id . ',id,colum_2,' . $this->column_2
]

Note: tested in Laravel 6.

Solution 2


Try this rule:
'data.ip' => 'required|unique:servers,ip,'.$this>id.'|unique:servers,hostname,'.$this->id

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read

Leave a Comment