How to use unique validation in laravel?
<p>I have comments table:</p>

<p><a href="https://i.stack.imgur.com/3yoww.png" rel="noreferrer"><img src="https://i.stack.imgur.com/3yoww.png" alt="enter image description here"></a></p>

<p>My Comment controller where its taking values from form and validating it and storing it in database.</p>

<pre><code>public function store(Request $request, $product_id)
    {
        $this-&gt;validate($request, array(
            'name' =&gt; 'required',
            'email'=&gt; 'required|email|unique:comments,product_id',
            'comment' =&gt; 'required',
            'rating' =&gt; 'required|integer'
            ));
        $product = Product::find($product_id);
        $comment = new Comment();
        $comment-&gt;name = $request-&gt;name;
        $comment-&gt;email = $request-&gt;email;
        $comment-&gt;comment = $request-&gt;comment;
        $comment-&gt;rating = $request-&gt;rating;
        $comment-&gt;product()-&gt;associate($product);

        $comment-&gt;save();
        Session::flash('success','Comment was added');
        return redirect()-&gt;route('product.show',[$product-&gt;id]);
    }
</code></pre>

<p><strong>I am trying to validate such that only unique email id is allowed to comment on every product_id that is if user has already commented on product_id 1 then the same user is not allowed to comment again on that id.</strong>  </p>

<p>I tried </p>

<pre><code>'email'=&gt; 'required|email|unique:comments,product_id'
</code></pre>

<p>But as u can see about same email id data was entered for same product_id.</p>

<p>A user can comment on n number of product_id page but cannot comment again once he has commented on that id.</p>

<p><strong>Is there a way to validate if email data has been entered in database for particular product_id then the same email is not allowed to submit the form.</strong></p>

<p><a href="https://i.stack.imgur.com/6nap3.png" rel="noreferrer"><img src="https://i.stack.imgur.com/6nap3.png" alt="enter image description here"></a></p>

<p>If different product_id then email can enter.</p>

<p>Thanks.</p>